Ad
  • Default User Avatar

    This comment is hidden because it contains spoiler information about the solution

  • Custom User Avatar
  • Custom User Avatar

    There's a few missing C# test cases

    [Test]
    public void NullSequence()
    {
      Assert.That(Kata.UniqueInOrder(null), Throws.InstanceOf<ArgumentNullException>());
      // OR (undefined requirement)
      Assert.That(Kata.UniqueInOrder(null), Is.Empty)
    }
    
    [Test]
    public void NullValue()
    {
      // Breaks solutions that use default as a placeholder value
      Assert.That(Kata.UniqueInOrder(new string[]{"Hello", null, null, "world"}), Is.EqualTo(new string[]{"Hello", null, "world"}));
    }
    
    [Test]
    public void LeadingZero()
    {
      // Breaks solutions that use default as a placeholder value
      Assert.That(Kata.UniqueInOrder(new int[]{0, 1, 2, 3}), Is.EqualTo(new int[]{0, 1, 2, 3}));
    }
    
    [Test]
    public void EmptyIntegerArray()
    {
      // Breaks solutions that use default as a placeholder value
      Assert.That(Kata.UniqueInOrder(Array.Empty<int>()), Is.EqualTo(Array.Empty<int>()));
    }
    
    [Test]
    public void MixedTypes()
    {
      // Make sure solutions don't use assumptions between types
      Assert.That(Kata.UniqueInOrder(new object[]{1, "2", 2, 2, "5", "5"}), Is.EqualTo(new object[]{1, "2", 2, "5"}));
    }
    
    private class Foo
    {
      public override bool Equals(object other) => other is Foo || other is Bar;
    }
    
    private class Bar
    {
      public override bool Equals(object other) => other is Foo || other is Bar;
    }
    
    [Test]
    public void RemovesDuplicateCustomTypes()
    {
      // Make sure solutions don't use assumptions between types
      Assert.That(Kata.UniqueInOrder(new object[]{new Foo(), 1, new Bar(), new Foo(), string.Empty}).Select(res => res.GetType()), Is.EqualTo(new object[]{typeof(Foo), typeof(1), typeof(Bar), typeof(string)}));
    }