USING OpenEdge.Core.Assert FROM PROPATH.
USING Progress.Collections.*.
USING OpenEdge.Core.Integer.
USING OpenEdge.Core.Decimal.

BLOCK-LEVEL ON ERROR UNDO, THROW.

CLASS TestMultipleImplements:

    @Test.
    METHOD PUBLIC VOID TestCompareToInteger():
        DEFINE VARIABLE obj1    AS MultipleImplements NO-UNDO.
        DEFINE VARIABLE obj2    AS MultipleImplements NO-UNDO.
        DEFINE VARIABLE result  AS INTEGER NO-UNDO.

        obj1 = NEW MultipleImplements(NEW OpenEdge.Core.Integer(10), NEW OpenEdge.Core.Decimal(100.00)).
        obj2 = NEW MultipleImplements(NEW OpenEdge.Core.Integer(20), NEW OpenEdge.Core.Decimal(200.00)).

        result = obj1:CompareTo(obj2:IntVal).
        Assert:Equals(result, -1).

        result = obj2:CompareTo(obj1:IntVal).
        Assert:Equals(result, 1).

        result = obj1:CompareTo(obj1:IntVal).
        Assert:Equals(result, 0).
    END METHOD.

    @Test.
    METHOD PUBLIC VOID TestCompareToDecimal():
        DEFINE VARIABLE obj1    AS MultipleImplements NO-UNDO.
        DEFINE VARIABLE obj2    AS MultipleImplements NO-UNDO.
        DEFINE VARIABLE result  AS INTEGER NO-UNDO.

        obj1 = NEW MultipleImplements(NEW OpenEdge.Core.Integer(10), NEW OpenEdge.Core.Decimal(100.00)).
        obj2 = NEW MultipleImplements(NEW OpenEdge.Core.Integer(20), NEW OpenEdge.Core.Decimal(200.00)).

        result = obj1:CompareTo(obj2:DecVal).
        Assert:Equals(result, -1).

        result = obj2:CompareTo(obj1:DecVal).
        Assert:Equals(result, 1).

        result = obj1:CompareTo(obj1:DecVal).
        Assert:Equals(result, 0).
    END METHOD.

    @Test.
    METHOD PUBLIC VOID TestMixedUsage():
        DEFINE VARIABLE obj    AS MultipleImplements NO-UNDO.
        DEFINE VARIABLE result AS INTEGER NO-UNDO.

        obj = NEW MultipleImplements(NEW OpenEdge.Core.Integer(15), NEW OpenEdge.Core.Decimal(150.00)).

        // Test integer comparisons 
        result = obj:CompareTo(NEW OpenEdge.Core.Integer(15)).
        Assert:Equals(result, 0).

        result = obj:CompareTo(NEW OpenEdge.Core.Integer(10)).
        Assert:Equals(result, 1).

        result = obj:CompareTo(NEW OpenEdge.Core.Integer(20)).
        Assert:Equals(result, -1).

        // Test decimal comparisons 
        result = obj:CompareTo(NEW OpenEdge.Core.Decimal(150.00)).
        Assert:Equals(result, 0).

        result = obj:CompareTo(NEW OpenEdge.Core.Decimal(100.00)).
        Assert:Equals(result, 1).

        result = obj:CompareTo(NEW OpenEdge.Core.Decimal(200.00)).
        Assert:Equals(result, -1).
    END METHOD.

END CLASS.
