• A best practice when templating this kind of algorithm is to
    make it generic, i.e. pass a range or [begin,end) as template parameters...
    Indeed, the initial parameter says 'iterable' :-)
    May also test with any kind of ordered iterable, so that one may use concepts one day and return {} if the values cannot be ordered ?

  • s = 'AAAABBBCCDAABBB'
    s = 'AAAABBBCCDAABBB1254888744'
    s = ['AA', 'A', '', '','B','B','C','c','b', '', 'None',5,5,'5']
    s = ['i', 't', 'e', 'r', 'a', 'b', 'l', 'e']
    s = ['A', 'B', 'C', 'D', 'A', 'A', 'D']
    s = ['A', 'A', None, None, None]
    s = ['5', 5]

    i run all above TCs in local env, and all producing the required result

    but when i run here, it failed with the below error
    expected undefined to deeply equal [ 'A', 'B', 'C', 'D', 'A', 'B' ]

  • 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)}));
    }
    
  • I don't see any tests with your given example. They're either all numbers, characters, or a string. (no mixed types)

    If such test was there, your first answer would probably be correct.

  • I got confused for data types .....

    like, example [1, 2, 3, 4, "4", 4, "4", "4"]

    should it be [1, 2, 3, 4, "4", 4, "4"]

    or

    [1, 2, 3, 4]

    ??

    I am using JavaScript.

  • Thanks a lot!

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

  • Thank you very much

  • For this kata, unique means that each character is repeated only once.

    For example, "abc" is valid, "abca" is not ('a' repeated twice)

    1. identify the characters that are repeated onece?
    2. Identify the characters that are speacial?
  • Can someone please explain what is meant by unique characters?

  • Tested for python.

    So unique_in_order(['A', 'A', '', '', '', 'B']) should be ['A', '', 'B']. But tests pass even if function returns ['A', '', '', '', 'B']. Conclusion: tests are missing for one corner case, so even incorrect code is accepted

    I guess that unique_in_order(['A', 'A', None, None, None, 'B']) == ['A', None, 'B'] is not covered by tests too.

    So I would suggest adding few more tests:

    test.it("should reduce empty string duplicates")
    test.assert_equals(unique_in_order(['A', 'A', '', '', '']), ['A', ''])  
    test.it("should reduce duplicates of `None`")
    test.assert_equals(unique_in_order(['A', 'A', None, None, None]), ['A', None])  
    
  • Could you be a bit more specific, or give an example?

  • Loading more items...