note description: "[ Testing suite for the DECIMAL class covering the operation capabilities on very large numbers. ]" author: "JSO & CD" date: "June 20 2019" revision: "1.00" class DECIMAL_LONG_TEST inherit ES_TEST create make feature {NONE} -- Initialization make do add_boolean_case (agent t1) add_boolean_case (agent t2) add_boolean_case (agent t3) add_boolean_case (agent t4) add_boolean_case (agent t5) add_boolean_case (agent t6) add_boolean_case (agent t7) add_boolean_case (agent t8) add_boolean_case (agent t9) add_boolean_case (agent t10) add_boolean_case (agent t11) add_boolean_case (agent t12) add_boolean_case (agent t13) add_boolean_case (agent t14) add_boolean_case (agent t15) add_boolean_case (agent t16) add_boolean_case (agent t17) add_boolean_case (agent t18) add_boolean_case (agent t19) add_boolean_case (agent t20) add_boolean_case (agent t21) add_boolean_case (agent t22) end feature -- Tests t1: BOOLEAN -- test operator < local d1: DECIMAL d2: DECIMAL do comment ("t1: less_than - Very Long Decimal Test") create d1.make_from_string ("42365473386374785637856437889849023849027453758346578365348929048012845738945364742378563489573495682359753657451565678345748643675895347861587618958736578134895637857348957348534895789345.5348738578498239758753753487457896346573465734897817587658349723897418567134865783464782357465234728947892561462389472356473561742389482653465123489234537561478239848915613476237842837418951347867234238561347623894792561488956346589478914791728957145612894792578947891247238947239472347238471479237849729347") create d2.make_from_string ("42365473386374785637856437889849023849027453758346578365348929048012845738945364742378563489573495682359753657451565678345748643675895347861587618958736578134895637857348957348534895789345.5348738578498239758753753487457896346573465734897817587658349723897418567134865783464782357465234728947892561462389472356473561742389482653465123489234537561478239848915613476237842837418951347867234238561347623894792561488956346589478914791728957145612894792578947891247238947239472347238471479237849729348") Result := d1 < d2 end t2: BOOLEAN local sn1, sn2, answer: DECIMAL do comment ("t2: plus - Very Long Positive + Very Long Negative") create sn1.make_from_string ("4635743657353.578395757439573577775767535734859364543534534645567578564564353426467456452675856245564675734645") create sn2.make_from_string ("-4635743657353.578395757439573577775767535734859364543534534645567578564564353426467456452675856245564675734645") answer := sn1 + sn2 Result := equal (answer.precise_out, "0") check Result end Result := equal (answer.out, "0.00") end t3: BOOLEAN -- test addition local sn1: DECIMAL sn2: DECIMAL answer: DECIMAL do comment ("t3: plus - Long Positive + Long Positive") create sn1.make_from_string ("3512765361.123812789378917389423472374238974892374982374") create sn2.make_from_string ("27893.234723894723897893274326578246826346") answer := sn1 + sn2 Result := equal (answer.precise_out, "3512793254.358536684102815282697798952485801238374982374") check Result end Result := equal (answer.out, "3512793254.36") end t4: BOOLEAN -- test subtraction local sn1: DECIMAL sn2: DECIMAL answer: DECIMAL do comment ("t4: subtract - Positive - Positive = 0") create sn1.make_from_string ("4635743657353.578395757439573577775767535734859364543534534645567578564564353426467456452675856245564675734645") create sn2.make_from_string ("4635743657353.578395757439573577775767535734859364543534534645567578564564353426467456452675856245564675734645") answer := sn1 - sn2 Result := equal (answer.precise_out, "0") check Result end Result := equal (answer.out, "0.00") end t5: BOOLEAN -- test subtraction local sn1: DECIMAL sn2: DECIMAL answer: DECIMAL do comment ("t5: subtract - Positive - Positive = Positive") create sn1.make_from_string ("3512765361.123812789378917389423472374238974892374982374") create sn2.make_from_string ("27893.234723894723897893274326578246826346") answer := sn1 - sn2 Result := equal (answer.precise_out, "3512737467.889088894655019496149145795992148546374982374") check Result end Result := equal (answer.out, "3512737467.89") end t6: BOOLEAN -- test subtraction local sn1: DECIMAL sn2: DECIMAL answer: DECIMAL do comment ("t6: subtract - Large Decimal - Large Decimal = Whole") create sn1.make_from_string ("999999.9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999") create sn2.make_from_string ("0.9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999") answer := sn1 - sn2 Result := equal (answer.precise_out, "999999") check Result end Result := equal (answer.out, "999999.00") end t7: BOOLEAN -- test subtraction local sn1: DECIMAL sn2: DECIMAL answer: DECIMAL do comment ("t7: subtract - Large Decimal - Large Whole = Large Decimal") create sn1.make_from_string ("999999.9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999") create sn2.make_from_string ("999999") create answer.make_from_string ("0.0") answer := sn1 - sn2 Result := equal (answer.precise_out, "0.9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999") check Result end Result := equal (answer.out, "1.00") end t8: BOOLEAN -- test subtraction local sn1: DECIMAL sn2: DECIMAL answer: DECIMAL do comment ("t8: subtract - Large Decimal - One = Large Decimal") create sn1.make_from_string ("84395743648584735894737856356473598473589674573452345789736734583847586374357823583585623562437538957677456437589375894736583654736578365783465782346578436578346578634576356436578436543567843657843657834658734656347564356473564735643567436578435636547365784365843657835") create sn2.make_from_string ("1") create answer.make_from_string ("0") answer := sn1 - sn2 Result := equal (answer.precise_out, "84395743648584735894737856356473598473589674573452345789736734583847586374357823583585623562437538957677456437589375894736583654736578365783465782346578436578346578634576356436578436543567843657843657834658734656347564356473564735643567436578435636547365784365843657834") check Result end Result := equal (answer.out, "84395743648584735894737856356473598473589674573452345789736734583847586374357823583585623562437538957677456437589375894736583654736578365783465782346578436578346578634576356436578436543567843657843657834658734656347564356473564735643567436578435636547365784365843657834.00") end t9: BOOLEAN -- test subtraction local sn1: DECIMAL sn2: DECIMAL answer: DECIMAL do comment ("t9: subtract - Very Large Decimal - 1 = Very Large Decimal") create sn1.make_from_string ("84395743648584735894737856356473598473589674573452345789736734583847586374357823583585623562437538957677456437589375894736583654736578365783465782346578436578346578634576356436578436543567843657843657834658734656347564356473564735643567436578435636547365784365843657835.5734895734895789347895634789573490583904587624875893534890589038649068908790356890585649578935734897689764897869057890576987935768573465893276857468978968234753897583495734895734895738945738945738943895738957357") create sn2.make_from_string ("1") create answer.make_from_string ("0") answer := sn1 - sn2 Result := equal (answer.precise_out, "84395743648584735894737856356473598473589674573452345789736734583847586374357823583585623562437538957677456437589375894736583654736578365783465782346578436578346578634576356436578436543567843657843657834658734656347564356473564735643567436578435636547365784365843657834.5734895734895789347895634789573490583904587624875893534890589038649068908790356890585649578935734897689764897869057890576987935768573465893276857468978968234753897583495734895734895738945738945738943895738957357") check Result end Result := equal (answer.out, "84395743648584735894737856356473598473589674573452345789736734583847586374357823583585623562437538957677456437589375894736583654736578365783465782346578436578346578634576356436578436543567843657843657834658734656347564356473564735643567436578435636547365784365843657834.57") end t10: BOOLEAN -- test subtraction local sn1: DECIMAL sn2: DECIMAL answer: DECIMAL do comment ("t10: subtract - One - Very Large Decimal = Very Large Negative Decimal") create sn1.make_from_string ("1") create sn2.make_from_string ("84395743648584735894737856356473598473589674573452345789736734583847586374357823583585623562437538957677456437589375894736583654736578365783465782346578436578346578634576356436578436543567843657843657834658734656347564356473564735643567436578435636547365784365843657835") answer := sn1 - sn2 Result := equal (answer.precise_out, "-84395743648584735894737856356473598473589674573452345789736734583847586374357823583585623562437538957677456437589375894736583654736578365783465782346578436578346578634576356436578436543567843657843657834658734656347564356473564735643567436578435636547365784365843657834") check Result end Result := equal (answer.out, "-84395743648584735894737856356473598473589674573452345789736734583847586374357823583585623562437538957677456437589375894736583654736578365783465782346578436578346578634576356436578436543567843657843657834658734656347564356473564735643567436578435636547365784365843657834.00") end t11: BOOLEAN -- test subtraction local sn1: DECIMAL sn2: DECIMAL answer: DECIMAL do comment ("t11: subtract - Small Long Decimal - One = Long Small Decimal") create sn1.make_from_string ("1.84395743648584735894737856356473598473589674573452345789736734583847586374357823583585623562437538957677456437589375894736583654736578365783465782346578436578346578634576356436578436543567843657843657834658734656347564356473564735643567436578435636547365784365843657835") create sn2.make_from_string ("1") create answer.make_from_string ("0") answer := sn1 - sn2 Result := equal (answer.precise_out, "0.84395743648584735894737856356473598473589674573452345789736734583847586374357823583585623562437538957677456437589375894736583654736578365783465782346578436578346578634576356436578436543567843657843657834658734656347564356473564735643567436578435636547365784365843657835") check Result end Result := equal (answer.out, "0.84") end t12: BOOLEAN -- test subtraction local sn1: DECIMAL sn2: DECIMAL answer: DECIMAL do comment ("t12: subtract - One - Small Long Decimal = Long Small Decimal") create sn1.make_from_string ("1") create sn2.make_from_string ("1.84395743648584735894737856356473598473589674573452345789736734583847586374357823583585623562437538957677456437589375894736583654736578365783465782346578436578346578634576356436578436543567843657843657834658734656347564356473564735643567436578435636547365784365843657835") answer := sn1 - sn2 Result := equal (answer.precise_out, "-0.84395743648584735894737856356473598473589674573452345789736734583847586374357823583585623562437538957677456437589375894736583654736578365783465782346578436578346578634576356436578436543567843657843657834658734656347564356473564735643567436578435636547365784365843657835") check Result end Result := equal (answer.out, "-0.84") end t13: BOOLEAN -- test multiplication local sn1, sn2: DECIMAL answer: DECIMAL do comment ("t13: multiplication - Very Large Whole * Very Small Decimal = 0.1") create sn1.make_from_string ("10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000") create sn2.make_from_string ("0.00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001") answer := sn1 * sn2 Result := equal (answer.precise_out, "0.1") check Result end Result := equal (answer.out, "0.10") end t14: BOOLEAN -- test multiplication local sn1, sn2: DECIMAL answer: DECIMAL do comment ("t14: multiplication - Very Large Multiplication (Whole Numbers)") create sn1.make_from_string ("100000000000000000000000000000000000000000000000000000000000000000000") create sn2.make_from_string ("200000000000000000000000000000000000000000000000000000000000000000000000000000000000000") answer := sn1 * sn2 Result := equal (answer.precise_out, "20000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000") check Result end Result := equal (answer.out, "20000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.00") end t15: BOOLEAN -- test multiplication local sn1, sn2: DECIMAL answer: DECIMAL do comment ("t15: multiplication - Very Large Decimal * Small Negative") create sn1.make_from_string ("4672836478263478263746273467826347826347862374678234234345664553465654646456.3442364646746456456567487867456576786864767867867645756564786847567567578567567575756756756757") create sn2.make_from_string ("-0.1") create answer.make_from_string ("0") answer := sn1 * sn2 Result := equal (answer.precise_out, "-467283647826347826374627346782634782634786237467823423434566455346565464645.63442364646746456456567487867456576786864767867867645756564786847567567578567567575756756756757") check Result end Result := equal (answer.out, "-467283647826347826374627346782634782634786237467823423434566455346565464645.63") end t16: BOOLEAN -- test division local sn1: DECIMAL sn2: DECIMAL answer: DECIMAL do comment ("t16: divide - Large Decimal / Large Decimal = Whole Number") create sn1.make_from_string ("84286620042684884206684.886622440020486648200846268420") create sn2.make_from_string ("42143310021342442103342.443311220010243324100423134210") answer := sn1 / sn2 Result := equal (answer.precise_out, "2") check Result end Result := equal (answer.out, "2.00") end t17: BOOLEAN -- test division local sn1: DECIMAL sn2: DECIMAL answer: DECIMAL do comment ("t17: divide - Large Decimal / -1 = -Large Decimal") create sn1.make_from_string ("7439758473585757575785757575783947538945.5904395843958439058439058439058439058349058439058439085394859430853904853985") create sn2.make_from_string ("-00001.00000000000000000000000000000000000000000000000000000") create answer.make_from_string ("7439758473585757575785757575783947538945.5904395843958439058439058439058439058349058439058439085394859430853904853985") answer := sn1 / sn2 Result := answer.precise_out.starts_with ("-7439758473585757575785757575783947538945.5904395843958439058439058439058439058349058439058439085394859430853904853985") assert_equal ("fail", "-7439758473585757575785757575783947538945.5904395843958439058439058439058439058349058439058439085394859430853904853985", answer.precise_out) check Result end Result := equal (answer.out, "-7439758473585757575785757575783947538945.59") end t18: BOOLEAN -- test division local sn1: DECIMAL sn2: DECIMAL answer: DECIMAL do comment ("t18: divide - Very Large Decimal / -Very Large Decimal = -1") create sn1.make_from_string ("7439758473585757575785757575783947538945.5904395843958439058439058439058439058349058439058439085394859430853904853985") create sn2.make_from_string ("-7439758473585757575785757575783947538945.5904395843958439058439058439058439058349058439058439085394859430853904853985") answer := sn1 / sn2 Result := equal (answer.precise_out, "-1") check Result end Result := equal (answer.out, "-1.00") end t19: BOOLEAN -- test division local sn1: DECIMAL sn2: DECIMAL answer: DECIMAL do comment ("t19: divide - Very Large Square Division") create sn1.make_from_string ("12345678987654321.000000000000000000000000000000000000000000000000000000000000") create sn2.make_from_string ("111111111.00000000000000000000000000000000000000") answer := sn1 / sn2 Result := equal (answer.precise_out, "111111111") check Result end Result := equal (answer.out, "111111111.00") end t20: BOOLEAN -- Long Multiplication test local d1, d2, answer: DECIMAL do comment ("t20: multiply - Very Large * Very Large (precision check)") d1 := create {attached DECIMAL}.make_from_string ("12345678901234567890123456789012345678901234567890123456789012345678901234567890") d2 := create {attached DECIMAL}.make_from_string ("12345678901234567890123456789012345678901234567890123456789012345678901234567890") answer := d1 * d2 Result := answer.precise_out ~ "152415787532388367504953515625666819450083828733760097552251181223112635269100012193273126047859425087639153757049236500533455762536198787501905199875019052100" assert_equal ("fail large multiplication", "152415787532388367504953515625666819450083828733760097552251181223112635269100012193273126047859425087639153757049236500533455762536198787501905199875019052100", answer.precise_out) check Result end end t21: BOOLEAN -- Long addition test local d1, d2, answer: DECIMAL do comment ("t21: addition - Very Large Integer + Very small Decimal") d1 := create {attached DECIMAL}.make_from_string ("12345678901234567890123456789012345678901234567890123456789012345678901234567890") d2 := create {attached DECIMAL}.make_from_string ("0.12345678901234567890123456789012345678901234567890123456789012345678901234567891") answer := d1 + d2 Result := answer.precise_out ~ "12345678901234567890123456789012345678901234567890123456789012345678901234567890.12345678901234567890123456789012345678901234567890123456789012345678901234567891" assert_equal ("fail large addition", "12345678901234567890123456789012345678901234567890123456789012345678901234567890.12345678901234567890123456789012345678901234567890123456789012345678901234567891", answer.precise_out) end t22: BOOLEAN -- Long addition test local d1, d2, answer: DECIMAL do comment ("t22: addition - Very Large Integer + Very small Decimal") d1 := create {attached DECIMAL}.make_from_string ("1000000000000000000000000000000000000000000000000000000000000000000000000000000000") d2 := create {attached DECIMAL}.make_from_string ("0.00000000000000000000000000000000000000000000000000000000000000000000000000000001") answer := d1 + d2 Result := answer.precise_out ~ "1000000000000000000000000000000000000000000000000000000000000000000000000000000000.00000000000000000000000000000000000000000000000000000000000000000000000000000001" assert_equal ("fail large addition", "1000000000000000000000000000000000000000000000000000000000000000000000000000000000.00000000000000000000000000000000000000000000000000000000000000000000000000000001", answer.precise_out) end end -- class DECIMAL_LONG_TEST
Generated by ISE EiffelStudio