Skip to content

Instantly share code, notes, and snippets.

using NSubstitute;
public interface IFoo
{
int Bar(int k);
void Foo();
void Foobar();
}
class Program
@boegholm
boegholm / BadList.cs
Created November 9, 2022 12:43
BadList
namespace BadListExercise
{
public class BadList
{
private class Node
{
public Node(int data)
{
Data = data;
}
@boegholm
boegholm / DKKDerivates.cs
Last active December 10, 2021 10:43
LinearlyConvertibleHierarchy
class SEK : IKrBasedCurrency<SEK>
{
public static decimal Factor => 0.75M;
public decimal Value { get; init; }
public SEK(){}
public SEK(decimal value){Value = value;}
public static implicit operator SEK(DKK v) => DKK.Change<SEK>(v);
public static implicit operator DKK(SEK v) => DKK.Change(v);
public static DKK operator +(SEK left, DKK right) => ((DKK)left) + right;
public override string ToString() => $"({this.GetType().Name}){Value}";
DKK kr = new DKK { Value = 14 };
Console.WriteLine(kr); // (DKR)14
USD usd = kr + kr;
Console.WriteLine(usd); // (USD)4
SEK sek = new SEK { Value = 14 };
Console.WriteLine(sek); // (SEK)14
Console.WriteLine((DKK)sek); // (DKK)10.5
public T Fibonacci<T>(T n) where T: IBasicOps<T>
{
if (n.Equals(T.Zero) || n.Equals(T.One))
return n;
return Fibonacci(n - T.One) + Fibonacci(n - (T.One + T.One));
}
void Foo() => Console.Write("Observer pattern");
void Bar() { Console.Write("For fun"); }
ISubject fun = null; //initialize before use :(
fun += Foo;
fun += () => Console.Write(" with fancy syntax ");
fun += Bar;
fun += () => Console.WriteLine(" and profit...");
fun.Notify();
@boegholm
boegholm / MultiFact.cs
Last active December 1, 2021 09:23
FactToTheory
[Fact]
public void Add_SumOfTwoZeros()
{
int a = 0, b = 0, expected = 0;
var c = new Calculator();
var actual = c.Add(a,b);
Assert.Equal(expected, actual);
}
[Fact]
public void Add_SumsOfTwoNumbers()
@boegholm
boegholm / CalculatorTests.cs
Last active November 24, 2021 22:38
XUnitMultiple
[Fact]
public void AddSumsTwoNumbersCommutatively()
{
int a = 1, b = 2, expected = 3;
var c = new Calculator();
int acutalAB = c.Add(a, b);
var actualBA = c.Add(b, a);
Assert.Multiple(
()=> Assert.Equal(expected, acutalAB),
@boegholm
boegholm / AForwardStream.cs
Created November 18, 2021 22:15
MagicDetectingStream
public abstract class AForwardStream : Stream
{
public abstract Stream SourceStream { get; }
public override bool CanRead => SourceStream.CanRead;
public override bool CanSeek => SourceStream.CanSeek;
public override bool CanWrite => SourceStream.CanWrite;
public override long Length => SourceStream.Length;
public override long Position { get => SourceStream.Position; set => SourceStream.Position = value; }
public override void Flush() => SourceStream.Flush();
public override int Read(byte[] buffer, int offset, int count) => SourceStream.Read(buffer, offset, count);
#include "framework.h"
#include "TPX1MouseCursorFix.h"
#define MAX_LOADSTRING 100
int APIENTRY wWinMain(_In_ HINSTANCE hInstance,
_In_opt_ HINSTANCE hPrevInstance,
_In_ LPWSTR lpCmdLine,
_In_ int nCmdShow)
{