Ejemplo n.º 1
0
def test_count_uniq():
    # Use a custom generator for testing
    def my_mod_range(n, mod=2):
        for i in range(n):
            yield i % mod

    assert 4 == sn.count_uniq([1, 2, 3, 4, 4, 3, 2, 1])
    assert 1 == sn.count_uniq((1, 1, 1))
    assert 3 == sn.count_uniq({1, 2, 3, 2, 3})
    assert 3 == sn.count_uniq({'a': 1, 'b': 2, 'c': 3})
    assert 2 == sn.count_uniq(my_mod_range(10))
    assert 3 == sn.count_uniq(my_mod_range(10, 3))

    # Test empty sequences
    assert 0 == sn.count_uniq([])
    assert 0 == sn.count_uniq({})
    assert 0 == sn.count_uniq(set())
    assert 0 == sn.count_uniq(my_mod_range(0))
    assert 0 == sn.count_uniq(range(0))

    # Test deferred expressions
    d = [1, 2, 2, 1]
    assert 2 == sn.count_uniq(sn.defer(d))
Ejemplo n.º 2
0
    def test_count_uniq(self):
        # Use a custom generator for testing
        def my_mod_range(n, mod=2):
            for i in range(n):
                yield i % mod

        self.assertEqual(4, sn.count_uniq([1, 2, 3, 4, 4, 3, 2, 1]))
        self.assertEqual(1, sn.count_uniq((1, 1, 1)))
        self.assertEqual(3, sn.count_uniq({1, 2, 3, 2, 3}))
        self.assertEqual(3, sn.count_uniq({'a': 1, 'b': 2, 'c': 3}))
        self.assertEqual(2, sn.count_uniq(my_mod_range(10)))
        self.assertEqual(3, sn.count_uniq(my_mod_range(10, 3)))

        # Test empty sequences
        self.assertEqual(0, sn.count_uniq([]))
        self.assertEqual(0, sn.count_uniq({}))
        self.assertEqual(0, sn.count_uniq(set()))
        self.assertEqual(0, sn.count_uniq(my_mod_range(0)))
        self.assertEqual(0, sn.count_uniq(range(0)))

        # Test deferred expressions
        d = [1, 2, 2, 1]
        self.assertEqual(2, sn.count_uniq(make_deferrable(d)))