import unittest

from dedupe import stable_unique


class DedupeTests(unittest.TestCase):
    def test_preserves_first_and_order(self):
        values = [{"id": 2, "v": "a"}, {"id": 1}, {"id": 2, "v": "b"}]
        self.assertEqual(stable_unique(values, lambda item: item["id"]), values[:2])

    def test_does_not_mutate_input(self):
        values = [[1], [1], [2]]
        before = [list(value) for value in values]
        stable_unique(values, tuple)
        self.assertEqual(values, before)


if __name__ == "__main__":
    unittest.main()
