#!/usr/bin/env qore

%requires ../../../../qlib/Util.qm
%requires ../../../../qlib/QUnit.qm

%new-style
%require-types
%enable-all-warnings

%exec-class UniqTest

public class UniqTest inherits QUnit::Test {
    constructor() : Test ("UniqTest", "1.0") {
        addTestCase ("Tests for uniq() function", \test_uniq());
        set_return_value(main());
    }

    test_uniq() {
        assertEq ((), uniq ());
        assertEq ((1,), uniq (1));
        assertEq ((1,2,3), uniq ((1,2,3)));
        assertEq ((1,2,3), uniq ((1,2,1,3,2,1)));
        assertEq (('a','b','c'), uniq (('a','b','c','b','a')));

        # test floats that can get aliased even when they are different
        # due to the default string conversion having limited precision
        float f0 = M_PI;
        float f1 = M_PI + 0.00000001;
        float f2 = M_PI + 0.000000001;
        assertTrue (f0 !== f1);
        assertTrue (f0 !== f2);
        assertEq ((f0, f1), uniq ((f0, f1)));
        code kod = sub () { uniq ((f0, f2)); };
        assertThrows ("UNIQ-ERROR", kod, ());
    }
}
