public void SplitShouldReturnNode1001WhenLeaf1() { // split(1) = ((1,0),(0,1)) Id one = new Id.Leaf(1); one.Split().Should().Be(new Id.Node(new Id.Node(1, 0), new Id.Node(0, 1))); }
Id DecodeId() { Id id = null; byte prefix1 = Scan(2); switch (prefix1) { case 0: // 0 | 1 byte v = Scan(1); id = new Id.Leaf(v); break; case 1: // (0,1) id = new Id.Node(0, DecodeId()); break; case 2: // (i,0) id = new Id.Node(DecodeId(), 0); break; case 3: // (l,r) id = new Id.Node(DecodeId(), DecodeId()); break; default: ThrowUnexpected(prefix1); break; } return(id); }
public void ImplicitConversionOperatorShouldReturnLeafWhenInteger() { Id i1 = new Id.Leaf(1); Id i2 = 1; i1.Equals(i2).Should().BeTrue(); }
public void SplitShouldReturnNode00WhenLeaf0() { // split(0) = (0,0) Id zero = new Id.Leaf(0); zero.Split().Should().Be(new Id.Node(0, 0)); }
public void EqualsShouldReturnFalseWhenComparingLeafsWithDifferentValues() { // Arrange Id i1 = new Id.Leaf(0); Id i2 = new Id.Leaf(1); // Act & Assert i1.Equals(i2).Should().BeFalse(); }
public void EqualsShouldReturnTrueWhenComparingLeafsWithSameValues() { // Arrange Id i1 = new Id.Leaf(0); Id i2 = new Id.Leaf(0); // Act & Assert i1.Equals(i2).Should().BeTrue(); }
public void NormalizeShouldReturniWhenLeafIsi() { // Arrange Id id = new Id.Leaf(1); // Act Id normalized = id.Normalize(); // Assert normalized.Should().Be((Id)1); }
public void GetHashCodeShouldNotMatchWhenLeafsHaveDifferentValues() { // Arrange // Arrange Id i1 = new Id.Leaf(0); Id i2 = new Id.Leaf(1); // Act int hash1 = i1.GetHashCode(); int hash2 = i2.GetHashCode(); // Assert hash1.Should().NotBe(hash2); }
public void GetHashCodeShouldMatchWhenLeafsHaveSameValues() { // Arrange // Arrange Id i1 = new Id.Leaf(0); Id i2 = new Id.Leaf(0); // Act int hash1 = i1.GetHashCode(); int hash2 = i2.GetHashCode(); // Assert hash1.Should().Be(hash2); }
public void MatchShouldInvokeLeafFuncWhenIdRepresentsLeaf() { // Arrange Id id = new Id.Leaf(0); Func <int, object> leafFn = Substitute.For <Func <int, object> >(); Func <Id, Id, object> nodeFn = Substitute.For <Func <Id, Id, object> >(); // Act id.Match(leafFn, nodeFn); // Assert leafFn.Received().Invoke(0); nodeFn.DidNotReceiveWithAnyArgs(); }
public void MatchShouldInvokeLeafActionWhenIdRepresentsLeaf() { // Arrange Id id = new Id.Leaf(0); Action <int> leafAction = Substitute.For <Action <int> >(); Action <Id, Id> nodeAction = Substitute.For <Action <Id, Id> >(); // Act id.Match(leafAction, nodeAction); // Assert leafAction.Received().Invoke(0); nodeAction.DidNotReceiveWithAnyArgs(); }