note description: "Summary description for {TEST_REL}." author: "Jackie Wang" date: "$Date$" revision: "$Revision$" class TEST_REL create make feature {NONE} -- Initialization make -- Run application. do setup 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) end setup -- Will be executed at the beginning of "run" in a test case. do common_setup end feature -- Initialization default_create -- Process instances of classes with no creation clause. -- (Default: do nothing.) -- (from ANY) do end feature {NONE} -- Access Execution_environment: EXECUTION_ENVIRONMENT -- An execution environment object. -- (from SHARED_EXECUTION_ENVIRONMENT) once create Result end feature -- Access generating_type: TYPE [detachable TEST_REL] -- Type of current object -- (type of which it is a direct instance) -- (from ANY) external "built_in" ensure -- from ANY generating_type_not_void: Result /= Void end generator: STRING_8 -- Name of current object's generating class -- (base class of the type of which it is a direct instance) -- (from ANY) external "built_in" ensure -- from ANY generator_not_void: Result /= Void generator_not_empty: not Result.is_empty end feature -- Comparison frozen deep_equal (a: detachable ANY; b: like arg #1): BOOLEAN -- Are a and b either both void -- or attached to isomorphic object structures? -- (from ANY) do if a = Void then Result := b = Void else Result := b /= Void and then a.is_deep_equal (b) end ensure -- from ANY instance_free: class shallow_implies_deep: standard_equal (a, b) implies Result both_or_none_void: (a = Void) implies (Result = (b = Void)) same_type: (Result and (a /= Void)) implies (b /= Void and then a.same_type (b)) symmetric: Result implies deep_equal (b, a) end frozen equal (a: detachable ANY; b: like arg #1): BOOLEAN -- Are a and b either both void or attached -- to objects considered equal? -- (from ANY) do if a = Void then Result := b = Void else Result := b /= Void and then a.is_equal (b) end ensure -- from ANY instance_free: class definition: Result = (a = Void and b = Void) or else ((a /= Void and b /= Void) and then a.is_equal (b)) end frozen is_deep_equal (other: TEST_REL): BOOLEAN -- Are Current and other attached to isomorphic object structures? -- (from ANY) require -- from ANY other_not_void: other /= Void external "built_in" ensure -- from ANY shallow_implies_deep: standard_is_equal (other) implies Result same_type: Result implies same_type (other) symmetric: Result implies other.is_deep_equal (Current) end is_equal (other: TEST_REL): BOOLEAN -- Is other attached to an object considered -- equal to current object? -- (from ANY) require -- from ANY other_not_void: other /= Void external "built_in" ensure -- from ANY symmetric: Result implies other ~ Current consistent: standard_is_equal (other) implies Result end frozen standard_equal (a: detachable ANY; b: like arg #1): BOOLEAN -- Are a and b either both void or attached to -- field-by-field identical objects of the same type? -- Always uses default object comparison criterion. -- (from ANY) do if a = Void then Result := b = Void else Result := b /= Void and then a.standard_is_equal (b) end ensure -- from ANY instance_free: class definition: Result = (a = Void and b = Void) or else ((a /= Void and b /= Void) and then a.standard_is_equal (b)) end frozen standard_is_equal (other: TEST_REL): BOOLEAN -- Is other attached to an object of the same type -- as current object, and field-by-field identical to it? -- (from ANY) require -- from ANY other_not_void: other /= Void external "built_in" ensure -- from ANY same_type: Result implies same_type (other) symmetric: Result implies other.standard_is_equal (Current) end feature -- Status report conforms_to (other: ANY): BOOLEAN -- Does type of current object conform to type -- of other (as per Eiffel: The Language, chapter 13)? -- (from ANY) require -- from ANY other_not_void: other /= Void external "built_in" end same_type (other: ANY): BOOLEAN -- Is type of current object identical to type of other? -- (from ANY) require -- from ANY other_not_void: other /= Void external "built_in" ensure -- from ANY definition: Result = (conforms_to (other) and other.conforms_to (Current)) end feature -- Duplication frozen clone (other: detachable ANY): like other obsolete "Use `twin' instead. [2017-05-31]" -- Void if other is void; otherwise new object -- equal to other -- -- For non-void other, clone calls copy; -- to change copying/cloning semantics, redefine copy. -- (from ANY) do if other /= Void then Result := other.twin end ensure -- from ANY instance_free: class equal: Result ~ other end copy (other: TEST_REL) -- Update current object using fields of object attached -- to other, so as to yield equal objects. -- (from ANY) require -- from ANY other_not_void: other /= Void type_identity: same_type (other) external "built_in" ensure -- from ANY is_equal: Current ~ other end frozen deep_clone (other: detachable ANY): like other obsolete "Use `deep_twin' instead. [2017-05-31]" -- Void if other is void: otherwise, new object structure -- recursively duplicated from the one attached to other -- (from ANY) do if other /= Void then Result := other.deep_twin end ensure -- from ANY instance_free: class deep_equal: deep_equal (other, Result) end frozen deep_copy (other: TEST_REL) -- Effect equivalent to that of: -- copy (other . deep_twin) -- (from ANY) require -- from ANY other_not_void: other /= Void do copy (other.deep_twin) ensure -- from ANY deep_equal: deep_equal (Current, other) end frozen deep_twin: TEST_REL -- New object structure recursively duplicated from Current. -- (from ANY) external "built_in" ensure -- from ANY deep_twin_not_void: Result /= Void deep_equal: deep_equal (Current, Result) end frozen standard_clone (other: detachable ANY): like other obsolete "Use `standard_twin' instead. [2017-05-31]" -- Void if other is void; otherwise new object -- field-by-field identical to other. -- Always uses default copying semantics. -- (from ANY) do if other /= Void then Result := other.standard_twin end ensure -- from ANY instance_free: class equal: standard_equal (Result, other) end frozen standard_copy (other: TEST_REL) -- Copy every field of other onto corresponding field -- of current object. -- (from ANY) require -- from ANY other_not_void: other /= Void type_identity: same_type (other) external "built_in" ensure -- from ANY is_standard_equal: standard_is_equal (other) end frozen standard_twin: TEST_REL -- New object field-by-field identical to other. -- Always uses default copying semantics. -- (from ANY) external "built_in" ensure -- from ANY standard_twin_not_void: Result /= Void equal: standard_equal (Result, Current) end frozen twin: TEST_REL -- New object equal to Current -- twin calls copy; to change copying/twinning semantics, redefine copy. -- (from ANY) external "built_in" ensure -- from ANY twin_not_void: Result /= Void is_equal: Result ~ Current end feature -- Basic operations add_boolean_case (v: PREDICATE) -- Add boolean function v. -- (from ES_TEST) require -- from ES_TEST v_valid: v /= Void do if cases = Void then initialize end if attached cases as cases1 then cases1.extend (create {ES_BOOLEAN_TEST_CASE}.make ("", v)) end end add_violation_case (v: PROCEDURE) -- Add boolean function v. -- (from ES_TEST) require -- from ES_TEST v_valid: v /= Void do if cases = Void then initialize end if attached cases as cases1 then cases1.extend (create {ES_VIOLATION_CASE}.make ("", v)) end end add_violation_case_with_tag (expected_tag: STRING_8; v: PROCEDURE) -- Add boolean function v. -- (from ES_TEST) require -- from ES_TEST v_valid: v /= Void do if cases = Void then initialize end if attached cases as cases1 then cases1.extend (create {ES_VIOLATION_CASE}.make_with_tag ("", v, expected_tag)) end end frozen as_attached: attached TEST_REL obsolete "Remove calls to this feature. [2017-05-31]" -- Attached version of Current. -- (Can be used during transitional period to convert -- non-void-safe classes to void-safe ones.) -- (from ANY) do Result := Current end frozen default: detachable TEST_REL -- Default value of object's type -- (from ANY) do end frozen default_pointer: POINTER -- Default value of type POINTER -- (Avoid the need to write p.default for -- some p of type POINTER.) -- (from ANY) do ensure -- from ANY instance_free: class end default_rescue -- Process exception for routines with no Rescue clause. -- (Default: do nothing.) -- (from ANY) do end frozen do_nothing -- Execute a null action. -- (from ANY) do ensure -- from ANY instance_free: class end feature {ES_SUITE} case_name: STRING_8 -- (from ES_TEST) attribute Result := "" end count: INTEGER_32 -- Number of test cases in Current. -- (from ES_TEST) do check attached cases as cases1 then Result := cases1.count end end create_case_name (case: ES_TEST_CASE; unkn: CELL [INTEGER_32]) -- (from ES_TEST) local ls: LIST [STRING_8] do ls := case.case_name.split (':'.to_character_32) if not case.case_name.has (':') or ls.is_empty then unkn.put (unkn.item + 1) case_name := "unknown_" + unkn.item.out + " -- use ':' in a `comment' in the test case" else case_name := ls.first end if attached name as n then case_name := n + "." + case_name end end failed_cases: LIST [STRING_8] -- List of the name of all the failed test cases. -- (from ES_TEST) local failed: ARRAYED_LIST [STRING_8] unkn: CELL [INTEGER_32] do create failed.make (10) create unkn.put (0) if attached cases as cases1 then across cases1 as it loop create_case_name (it.item, unkn) if not it.item.passed then failed.extend (case_name) end end end Result := failed end get_test_name: STRING_8 -- Get unit test name. -- (from ES_TEST) do if name /= Void then check attached name as n then Result := n end else Result := "default_name" end end initialize -- Initialize Current. -- (from ES_TEST) do create cases.make name := generating_type.name.as_string_8 create descriptions.make end passed_cases: LIST [STRING_8] -- List of the name of all the successful test cases. -- (from ES_TEST) local success: ARRAYED_LIST [STRING_8] unkn: CELL [INTEGER_32] do create success.make (10) create unkn.put (0) if attached cases as cases1 then across cases1 as it loop create_case_name (it.item, unkn) if it.item.passed then success.extend (case_name) end end end Result := success end run_es_test -- Run tests in cases. -- (from ES_TEST) local problem: BOOLEAN last_index: INTEGER_32 do if attached cases as cases1 then if not problem then number_of_tests := 0 number_passed_tests := 0 check attached get_test_name as test_name then safe_put_string (test_name + "%N") end else safe_put_string ("***FAILED Problem in 'setup' or 'teardown' features%N") if show_err then check attached cases1.item as item1 attached item1.exception_trace as et then safe_put_string ("%N" + et + "%N") end end end from if not problem then cases1.start else if cases1.valid_cursor_index (last_index) then cases1.go_i_th (last_index) end end until cases1.after loop class_variable_comment_string := "no comment" setup check attached cases1.item as item1 then item1.run teardown check attached class_variable_comment_string as cvc then item1.set_case_name (cvc) end check attached to_message_string (item1) as ms then safe_put_string (ms + "%N") end number_of_tests := number_of_tests + 1 if item1.passed then number_passed_tests := number_passed_tests + 1 end end cases1.forth end end to_html (get_html_name) check_browser rescue check attached cases as cases1 then problem := True cases1.forth last_index := cases1.index retry end end to_html (output_file_name: STRING_8) -- Generate HTML report with details. -- (from ES_TEST) require -- from ES_TEST output_file_name_valid: output_file_name /= Void local gen: ES_SUITE do create gen gen.add_test (Current) gen.pass_values (show_err, browser, name) gen.to_html (output_file_name) end to_message_string (item: ES_TEST_CASE): STRING_8 -- Text represenation of a test case. -- (from ES_TEST) require -- from ES_TEST arg_not_void: item /= Void do check attached cases as cases1 then create Result.make_empty if item.passed then Result.append_string (" PASSED ") else Result.append_string ("***FAILED ") end check attached cases1.item as item1 then if item.contract_violated then check attached item1.meaning (item1.violation_type) as meaning then Result.append_string ("VIOL " + "#" + meaning + "#") end else Result.append_string ("NO VIOL ") end Result.append_string (item1.case_name) if show_err then check attached item1.violation_tag as tag then Result.append_string ("%N" + tag) end end end end ensure -- from ES_TEST result_not_void: Result /= Void result_not_empty: not Result.is_empty end feature browser: BOOLEAN -- (from ES_TESTABLE) check_browser -- Run the browser on the generated HTML. -- (from ES_TESTABLE) do check attached get_html_name end if browser then if {PLATFORM}.is_windows then Execution_environment.launch ("%"explorer%" " + get_html_name + "%"") elseif {PLATFORM}.is_mac then Execution_environment.launch ("open" + " '" + get_html_name + "'") else check {PLATFORM}.is_unix end Execution_environment.launch ("xdg-open" + " '" + get_html_name + "'") end end end curr_os_dir_separator: CHARACTER_8 -- Return path separator for current OS. -- (from ES_TESTABLE) do Result := (create {OPERATING_ENVIRONMENT}).Directory_separator ensure -- from ES_TESTABLE separator_is_a_slash: Result = '/' or Result = '\' end default_html_name: detachable STRING_8 -- (from ES_TESTABLE) get_html_name: STRING_8 -- Return the name of the default html for this unit test. -- (from ES_TESTABLE) do if default_html_name /= Void then check attached default_html_name as d then Result := d.twin end else Result := (generating_type.name + ".html").as_string_8 end end number_of_tests: INTEGER_32 -- (from ES_TESTABLE) number_passed_tests: INTEGER_32 -- (from ES_TESTABLE) print_console_report -- Print a summary of all the test case results to the console. -- (from ES_TESTABLE) local failed: LIST [STRING_8] success: LIST [STRING_8] passed, total: INTEGER_32 do failed := failed_cases success := passed_cases passed := success.count total := success.count + failed.count Io.put_string (create {STRING_8}.make_filled ('=', 60)) Io.put_new_line safe_put_string ("passing tests%N") across success as it loop safe_put_string ("> " + it.item + "%N") end safe_put_string ("failing tests%N") across failed as it loop safe_put_string ("> " + it.item + "%N") end safe_put_string (passed.out + "/" + total.out + " passed%N") if number_of_tests = number_passed_tests then safe_put_string ("passed%N") else safe_put_string ("failed%N") end end print_to_screen (message: STRING_8) -- Prints the message to the screen, handles both GUI and standard output. -- (from ES_TESTABLE) do safe_put_string (message) end run_espec -- New feature instead of run_all. -- (from ES_TESTABLE) local problem: BOOLEAN do if not problem then run_es_test print_console_report end rescue problem := True print_to_screen ("Error: No test cases found, Please add ES_TEST classes to the class that inherits from ES_SUITE%N") retry end safe_put_string (message: STRING_8) -- Socket.putstring with exception handling. -- (from ES_TESTABLE) do print (message) end set_error_report (v: BOOLEAN) -- Show the contract violations if set to true. -- (from ES_TESTABLE) do show_err := v end set_html_name (s: STRING_8) -- Set the output html name. -- (from ES_TESTABLE) do default_html_name := s end show_browser -- Show the default browser. -- (from ES_TESTABLE) do browser := True end show_err: BOOLEAN -- (from ES_TESTABLE) show_errors -- Print error traces to the output. -- (from ES_TESTABLE) do show_err := True end feature -- Agent functions is_person (pair: PAIR [PERSON, CAR]; p: PERSON): BOOLEAN -- (from COMMON_SETUP) do Result := pair.first ~ p end feature -- Attributes common_setup -- (from COMMON_SETUP) do create p1.make ("p1") create p2.make ("p2") create p3.make ("p3") create p4.make ("p4") create m1.make ("m1") create m2.make ("m2") create m3.make ("m3") create m4.make ("m4") end m1: CAR -- (from COMMON_SETUP) m2: CAR -- (from COMMON_SETUP) m3: CAR -- (from COMMON_SETUP) m4: CAR -- (from COMMON_SETUP) p1: PERSON -- (from COMMON_SETUP) p2: PERSON -- (from COMMON_SETUP) p3: PERSON -- (from COMMON_SETUP) p4: PERSON -- (from COMMON_SETUP) feature -- Output Io: STD_FILES -- Handle to standard file setup -- (from ANY) once create Result Result.set_output_default ensure -- from ANY instance_free: class io_not_void: Result /= Void end out: STRING_8 -- New string containing terse printable representation -- of current object -- (from ANY) do Result := tagged_out ensure -- from ANY out_not_void: Result /= Void end print (o: detachable ANY) -- Write terse external representation of o -- on standard output. -- (from ANY) do if o /= Void then Io.put_string (o.out) end ensure -- from ANY instance_free: class end frozen tagged_out: STRING_8 -- New string containing terse printable representation -- of current object -- (from ANY) external "built_in" ensure -- from ANY tagged_out_not_void: Result /= Void end feature -- Platform Operating_environment: OPERATING_ENVIRONMENT -- Objects available from the operating system -- (from ANY) once create Result ensure -- from ANY instance_free: class operating_environment_not_void: Result /= Void end feature {NONE} -- Retrieval frozen internal_correct_mismatch -- Called from runtime to perform a proper dynamic dispatch on correct_mismatch -- from MISMATCH_CORRECTOR. -- (from ANY) local l_msg: STRING_8 l_exc: EXCEPTIONS do if attached {MISMATCH_CORRECTOR} Current as l_corrector then l_corrector.correct_mismatch else create l_msg.make_from_string ("Mismatch: ") create l_exc l_msg.append (generating_type.name) l_exc.raise_retrieval_exception (l_msg) end end feature {NONE} -- setup and teardown assert (a_name: STRING_8; condition: BOOLEAN; actual: detachable ANY) -- (from ES_TEST) local l_line1, l_line2: attached STRING_8 actual_out: STRING_8 cv: CHECK_VIOLATION do if not condition then if actual /= Void then actual_out := actual.out else actual_out := "Void" end l_line1 := Html_start_code + "Assert Violation: " + a_name + Html_end_code l_line2 := Html_start_code + "Object:   " + actual_out + Html_end_code class_variable_comment_string.append (l_line1 + l_line2) create cv cv.set_description (a_name) cv.raise end end assert_equal (a_name: STRING_8; expected, actual: detachable ANY) -- (from ES_TEST) local l_line1, l_line2, l_line3: STRING_8 expected_out, actual_out: STRING_8 cv: CHECK_VIOLATION do if expected /~ actual then if expected /= Void then expected_out := expected.out else expected_out := "Void" end if actual /= Void then actual_out := actual.out else actual_out := "Void" end l_line1 := Html_start_code + "Assert Equal Violation: " + a_name + Html_end_code l_line2 := Html_start_code + "Expected: " + expected_out + Html_end_code l_line3 := Html_start_code + "Actual:   " + actual_out + Html_end_code class_variable_comment_string.append (l_line1 + l_line2 + l_line3) create cv cv.set_description (a_name) cv.raise end end assert_not_equal (a_name: STRING_8; expected, actual: detachable ANY) -- (from ES_TEST) local l_line1, l_line2, l_line3: attached STRING_8 expected_out, actual_out: STRING_8 cv: CHECK_VIOLATION do if expected ~ actual then if expected /= Void then expected_out := expected.out else expected_out := "Void" end if actual /= Void then actual_out := actual.out else actual_out := "Void" end l_line1 := Html_start_code + "Assert NOT Equal Violation: " + a_name + Html_end_code l_line2 := Html_start_code + "Expected: " + expected_out + Html_end_code l_line3 := Html_start_code + "Actual:   " + actual_out + Html_end_code class_variable_comment_string.append (l_line1 + l_line2 + l_line3) create cv cv.set_description (a_name) cv.raise end end comment (s: STRING_8) -- Adds s to descriptions. -- (from ES_TEST) do class_variable_comment_string := s end Html_end_code: STRING_8 = "</code>" -- (from ES_TEST) Html_start_code: STRING_8 = "<br><code>" -- (from ES_TEST) Space: STRING_8 = " " -- (from ES_TEST) sub_comment (s: STRING_8) -- Adds s to comments. -- (from ES_TEST) do class_variable_comment_string.append ("%N" + s) end teardown -- Will be executed at the end of "run" in a test case. -- (from ES_TEST) do end feature -- tests t1: BOOLEAN local r, r1: REL [PERSON, CAR] r_inv: REL [CAR, PERSON] img, s: SET [CAR] do comment ("t1: basic relational operations") create r.make_empty Result := # r = 0 check Result end r.extend (create {PAIR [PERSON, CAR]}.make_from_tuple ([p1, m1])) r.extend (create {PAIR [PERSON, CAR]}.make_from_tuple ([p1, m2])) r.union (create {REL [PERSON, CAR]}.make_from_tuple_array (<<[p1, m3], [p1, m4]>>)) create r1.make_from_tuple_array (<<[p1, m3], [p1, m4], [p1, m1]>>) Result := r /~ r1 and then r1 |<: r and then not (r |<: r1) check Result end r1 := r1.extended (create {PAIR [PERSON, CAR]}.make_from_tuple ([p1, m2])) Result := r ~ r1 and then r1 |<: r and then r |<: r1 check Result end create s.make_from_array (<<m2, m1, m3, m4>>) img := r1.image (p1) Result := img ~ s check Result end r_inv := r.inverse Result := r_inv ~ create {REL [CAR, PERSON]}.make_from_tuple_array (<<[m4, p1], [m2, p1], [m1, p1], [m3, p1]>>) check Result end Result := r_inv.inverse ~ r check Result end end t2: BOOLEAN local er, r, r1, r2: REL [PERSON, CAR] es, s1, s2, s12, s3, s123: SET [PERSON] do comment ("t2: domain restriction and subtraction") create s1.make_from_array (<<p1>>) create s2.make_from_array (<<p2>>) create s12.make_from_array (<<p1, p2>>) create s3.make_from_array (<<p3>>) create s123.make_from_array (<<p1, p2, p3>>) create r1.make_from_tuple_array (<<[p1, m1], [p1, m4]>>) create r2.make_from_tuple_array (<<[p2, m3], [p2, m2]>>) r := r1.unioned (r2) Result := r |< s1 ~ r1 and then r |<< s1 ~ r2 and then ((r |< s1) |\/| (r |<< s1)) ~ r check Result end Result := r |< s2 ~ r2 and then r |<< s2 ~ r1 and then ((r |< s2) |\/| (r |<< s2)) ~ r check Result end create er.make_empty Result := r |< s12 ~ r and then r |<< s12 ~ er and then ((r |< s12) |\/| (r |<< s12)) ~ r check Result end Result := r |< s3 ~ er and then r |<< s3 ~ r and then ((r |< s3) |\/| (r |<< s3)) ~ r check Result end Result := r |< s123 ~ r and then r |<< s123 ~ er and then ((r |< s123) |\/| (r |<< s123)) ~ r check Result end create es.make_empty Result := r |< es ~ er and then r |<< es ~ r and then ((r |< es) |\/| (r |<< es)) ~ r check Result end end t3: BOOLEAN local er, r, r1, r2: REL [PERSON, CAR] es, s1, s2, s12, s3, s123: SET [CAR] do comment ("t3: range restriction and subtraction") create s1.make_from_array (<<m1>>) create s2.make_from_array (<<m2>>) create s12.make_from_array (<<m1, m2>>) create s3.make_from_array (<<m3>>) create s123.make_from_array (<<m1, m2, m3>>) create r1.make_from_tuple_array (<<[p1, m1], [p4, m1]>>) create r2.make_from_tuple_array (<<[p3, m2], [p2, m2]>>) r := r1.unioned (r2) Result := r |> s1 ~ r1 and then r |>> s1 ~ r2 and then ((r |> s1) |\/| (r |>> s1)) ~ r check Result end Result := r |> s2 ~ r2 and then r |>> s2 ~ r1 and then ((r |> s2) |\/| (r |>> s2)) ~ r check Result end create er.make_empty Result := r |> s12 ~ r and then r |>> s12 ~ er and then ((r |> s12) |\/| (r |>> s12)) ~ r check Result end Result := r |> s3 ~ er and then r |>> s3 ~ r and then ((r |> s3) |\/| (r |>> s3)) ~ r check Result end Result := r |> s123 ~ r and then r |>> s123 ~ er and then ((r |> s123) |\/| (r |>> s123)) ~ r check Result end create es.make_empty Result := r |> es ~ er and then r |>> es ~ r and then ((r |> es) |\/| (r |>> es)) ~ r check Result end end t4: BOOLEAN local rel, fun, inj: REL [PERSON, CAR] do comment ("t4: is_function and is_injection") create rel.make_from_tuple_array (<<[p1, m1], [p2, m2], [p3, m3], [p1, m4]>>) Result := not (rel.is_function or rel.is_injection) check Result end create fun.make_from_tuple_array (<<[p1, m1], [p2, m2], [p3, m3], [p4, m1]>>) Result := fun.is_function and not fun.is_injection check Result end create inj.make_from_tuple_array (<<[p1, m1], [p2, m2], [p3, m3], [p4, m4]>>) Result := inj.is_function and inj.is_injection check Result end end t5: BOOLEAN local er, r1, r2, r3, r4, r5, r6, r7: REL [PERSON, CAR] s: SET [PERSON] do comment ("t5: relationl override") create er.make_empty create r1.make_from_tuple_array (<<[p1, m1], [p2, m2], [p3, m3]>>) Result := er |<+ r1 ~ r1 and r1 |<+ er ~ r1 and er |<+ er ~ er check Result end create r2.make_from_tuple_array (<<[p1, m2], [p2, m3], [p2, m4]>>) create s.make_from_array (<<p1, p2>>) r3 := r1.domain_subtracted (s).unioned (r2) r4 := r1.domain_restricted (r1.domain |\ s).unioned (r2) Result := r1 |<+ r2 ~ r3 and r1 |<+ r2 ~ r4 check Result end create r5.make_from_tuple_array (<<[p4, m4], [p4, m1]>>) create s.make_from_array (<<p4>>) r6 := r1.domain_subtracted (s).unioned (r5) r7 := r1.domain_restricted (r1.domain |\ s).unioned (r5) Result := r1 |<+ r5 ~ r6 and r1 |<+ r5 ~ r7 check Result end end t6: BOOLEAN local r, r1, r2: REL [PERSON, CAR] do comment ("t6: relation comprehension") create r.make_from_tuple_array (<<[p1, m1], [p2, m2], [p3, m3], [p1, m4], [p4, m4]>>) r1 := r.domain_restricted (create {SET [PERSON]}.make_from_array (<<p1>>)) r2 := r.comprehension (agent is_person (?, p1)) Result := r1 ~ r2 check Result end end t7: BOOLEAN local r, r_: REL [PERSON, CAR] do comment ("t7: item and remove") create r.make_from_tuple_array (<<[p1, m1], [p2, m2], [p3, m3]>>) r.choose_item Result := r.item.first ~ p3 and r.item.second ~ m3 check Result end r.remove_item r.choose_item create r_.make_from_tuple_array (<<[p1, m1], [p2, m2]>>) Result := r ~ r_ and then r.item.first ~ p2 and r.item.second ~ m2 check Result end r.extend (create {PAIR [PERSON, CAR]}.make_from_tuple ([p4, m4])) r.choose_item create r_.make_from_tuple_array (<<[p4, m4], [p1, m1], [p2, m2]>>) Result := r ~ r_ and then r.item.first ~ p4 and r.item.second ~ m4 check Result end r.subtract (create {PAIR [PERSON, CAR]}.make_from_tuple ([p2, m2])) r.choose_item create r_.make_from_tuple_array (<<[p4, m4], [p1, m1]>>) Result := r ~ r_ and then r.item.first ~ p4 and r.item.second ~ m4 check Result end end t8: BOOLEAN local r, r1, r2, r3: REL [PERSON, CAR] s1, s2, s12, s3, s123: SET [PERSON] ap: ARRAY [TUPLE [PERSON, CAR]] do comment ("t8: relation as tupled array") create s1.make_from_array (<<p1>>) create s2.make_from_array (<<p2>>) create s12.make_from_array (<<p1, p2>>) create s3.make_from_array (<<p3>>) create s123.make_from_array (<<p1, p2, p3>>) r1 := create {attached REL [PERSON, CAR]}.make_from_tuple_array (<<[p1, m1], [p1, m4]>>) r2 := create {attached REL [PERSON, CAR]}.make_from_tuple_array (<<[p2, m3], [p2, m2]>>) r := r1.unioned (r2) Result := r |< s1 ~ r1 and then r |<< s1 ~ r2 and then ((r |< s1) |\/| (r |<< s1)) ~ r check Result end create r3.make_from_tuple_array (<<[p1, m1], [p1, m4]>>) ap := <<[p1, m1], [p1, m4]>> ap.compare_objects ap.do_all (agent {TUPLE [PERSON, CAR]}.compare_objects) Result := r1.as_array ~ ap check Result end end t9: BOOLEAN local r: REL [PERSON, CAR] sc: SET [CAR] do comment ("t8: test image as a set") r := create {attached REL [PERSON, CAR]}.make_from_tuple_array (<<[p1, m1], [p1, m4], [p2, m3]>>) sc := create {attached SET [CAR]}.make_from_array (<<m1, m4>>) Result := r [p1] ~ sc check Result end end feature {ES_HTML_GEN_SUITE} --test cases cases: detachable LINKED_LIST [ES_TEST_CASE] -- (from ES_TEST) class_variable_comment_string: STRING_8 -- (from ES_TEST) attribute Result := "" end descriptions: detachable LINKED_LIST [STRING_8] -- (from ES_TEST) name: detachable STRING_8 -- (from ES_TEST) invariant -- from ANY reflexive_equality: standard_is_equal (Current) reflexive_conformance: conforms_to (Current) end -- class TEST_REL
Generated by ISE EiffelStudio