note description: "[ Testing suite for the RATIONAL Class covering the power, square, gcd, reciprocal, v_divide, real_divide_round_to, round_to, opposite, and identity operation capabilities. ]" author: "Connor Dear, Jonathan Ostroff" date: "June 10 2019" revision: "1.00" class RATIONAL_SECONDARY_OPERATION_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) end feature -- Tests t1: BOOLEAN -- Square and Power local r1, r2: RATIONAL do comment ("t1: Square and Power - Positive and Negative Cases") r1 := create {attached RATIONAL}.make_from_string ("7/13") r2 := create {attached RATIONAL}.make_from_string ("9/-5") check r1.square ~ create {RATIONAL}.make_from_string ("49/169") and r1.square ~ create {RATIONAL}.make_from_string ("-49/-169") end check r2.square ~ create {RATIONAL}.make_from_string ("81/25") and r2.square ~ create {RATIONAL}.make_from_string ("-81/-25") end check r1 ^ 2 ~ r1.square end check r2 ^ 2 ~ r2.square end check r1 ^ 3 ~ create {RATIONAL}.make_from_string ("343/2197") end check r2 ^ 3 ~ create {RATIONAL}.make_from_string ("-729/125") end check r1 ^ -2 ~ create {RATIONAL}.make_from_string ("169/49") end check r2 ^ -2 ~ create {RATIONAL}.make_from_string ("25/81") end check r1 ^ -3 ~ create {RATIONAL}.make_from_string ("2197/343") end Result := r2 ^ -3 ~ create {RATIONAL}.make_from_string ("-125/729") and r2 ^ -3 ~ create {RATIONAL}.make_from_string ("125/-729") end t2: BOOLEAN -- Reciprocal local r1: RATIONAL do comment ("t2: reciprocal test") r1 := create {attached RATIONAL}.make_from_string ("111/123") Result := r1.reciprocal ~ create {RATIONAL}.make_from_string ("123/111") check Result end r1 := create {attached RATIONAL}.make_from_string ("-111/123") Result := r1.reciprocal ~ create {RATIONAL}.make_from_string ("-123/111") check Result end r1 := create {attached RATIONAL}.make_from_string ("111/-123") Result := r1.reciprocal ~ create {RATIONAL}.make_from_string ("123/-111") check Result end r1 := create {attached RATIONAL}.make_from_string ("-111/-123") Result := r1.reciprocal ~ create {RATIONAL}.make_from_string ("-123/-111") check Result end end t3: BOOLEAN -- Opposite / Negate local r1: RATIONAL do comment ("t3: opposite/negate test") r1 := create {attached RATIONAL}.make_from_string ("111/123") Result := r1.opposite ~ create {RATIONAL}.make_from_string ("-111/123") check Result end r1 := create {attached RATIONAL}.make_from_string ("-111/123") Result := r1.opposite ~ create {RATIONAL}.make_from_string ("111/123") check Result end r1 := create {attached RATIONAL}.make_from_string ("111/-123") Result := r1.opposite ~ create {RATIONAL}.make_from_string ("111/123") check Result end r1 := create {attached RATIONAL}.make_from_string ("-111/-123") Result := r1.opposite ~ create {RATIONAL}.make_from_string ("-111/123") check Result end end t4: BOOLEAN -- abs/absolute local r1: RATIONAL do comment ("t4: abs/absolute - Positive and Negative Cases ") r1 := create {attached RATIONAL}.make_from_string ("111/123") Result := r1.abs ~ create {RATIONAL}.make_from_string ("111/123") check Result end r1 := create {attached RATIONAL}.make_from_string ("-111/123") Result := r1.abs ~ create {RATIONAL}.make_from_string ("111/123") check Result end r1 := create {attached RATIONAL}.make_from_string ("111/-123") Result := r1.abs ~ create {RATIONAL}.make_from_string ("111/123") check Result end r1 := create {attached RATIONAL}.make_from_string ("-111/-123") Result := r1.abs ~ create {RATIONAL}.make_from_string ("111/123") check Result end end t5: BOOLEAN -- canonicalize local r1: RATIONAL do comment ("t5: canonicalize - Positive, Negative, Zero Cases") create r1.make_from_string ("2/4") r1.canonicalize Result := r1 ~ create {RATIONAL}.make_from_string ("1/2") check Result end create r1.make_from_string ("3/-9") r1.canonicalize Result := r1 ~ create {RATIONAL}.make_from_string ("1/-3") check Result end create r1.make_from_string ("-4/16") r1.canonicalize Result := r1 ~ create {RATIONAL}.make_from_string ("-1/4") check Result end create r1.make_from_string ("-5/-50") r1.canonicalize Result := r1 ~ create {RATIONAL}.make_from_string ("1/10") check Result end create r1.make_from_string ("0/-50") r1.canonicalize Result := r1 ~ create {RATIONAL}.make_from_string ("0/1") check Result end end end -- class RATIONAL_SECONDARY_OPERATION_TEST
Generated by ISE EiffelStudio