note
	description: "Summary description for {INT_ADVANCED_TESTS}."
	author: ""
	date: "$Date$"
	revision: "$Revision$"

class 
	INT_ADVANCED_TEST

inherit
	ES_TEST

create 
	make

feature {NONE} 

	make
		do
			add_boolean_case (agent t1)
			add_boolean_case (agent t2)
			add_boolean_case (agent t3)
		end
	
feature -- Misc. Advanced Testing

	Max_value: INTEGER_64 = 9223372036854775807

	Min_value: INTEGER_64 = -9223372036854775808

	max64_plus_one: BIG_INTEGER
		attribute
			Result := create {attached BIG_INTEGER}.make_from_string ("9223372036854775808")
		end

	min64_minus_one: BIG_INTEGER
		attribute
			Result := create {attached BIG_INTEGER}.make_from_string ("-9223372036854775809")
		end

	t1: BOOLEAN
			-- Proof of larger than int64 capabilities
		local
			imin, imax: INTEGER_64
			one, iminm, imaxp: BIG_INTEGER
			max64, min64: BIG_INTEGER
		do
			comment ("t1: int64 rolls over, but not big int")
			create max64.make_from_integer64 (9223372036854775807)
			create min64.make_from_integer64 (-9223372036854775808)
			one := create {attached BIG_INTEGER}.make_from_string ("1")
			imax := Max_value + 1
			Result := imax = -9223372036854775808
			check
					Result
			end
			imin := Min_value - 1
			Result := imin = 9223372036854775807
			check
					Result
			end
			imaxp := max64 + one
			Result := imaxp ~ max64_plus_one
			check
					Result
			end
			iminm := min64 - one
			Result := iminm ~ min64_minus_one
			check
					Result
			end
		end

	t2: BOOLEAN
			-- Order of Operations test
		local
			i1, i2, i3, i4: BIG_INTEGER
		do
			comment ("t2: Multiple Operations")
			i1 := create {attached BIG_INTEGER}.make_from_string ("4")
			i2 := create {attached BIG_INTEGER}.make_from_string ("6")
			i3 := create {attached BIG_INTEGER}.make_from_string ("2")
			i4 := i1 * i2 // i3 ^ 3
			Result := i4 ~ create {BIG_INTEGER}.make_from_string ("3")
		end

	t3: BOOLEAN
			-- Conversion Test
		local
			i1, i2: BIG_INTEGER
			s1: STRING_8
			i64: INTEGER_64
			i32: INTEGER_32
		do
			comment ("t3: Conversion - String, Int32, Int64")
			create i1.make_from_string ("5")
			s1 := "6"
			i64 := 2147483648
			i32 := 3
			Result := i1 + create {BIG_INTEGER}.make_from_integer32 (6) ~ create {BIG_INTEGER}.make_from_integer32 (11)
			check
					Result
			end
			i2 := i1 + create {BIG_INTEGER}.make_from_integer32 (i32) + create {BIG_INTEGER}.make_from_string (s1) + create {BIG_INTEGER}.make_from_integer64 (i64)
			Result := i1 + create {BIG_INTEGER}.make_from_string (s1) + create {BIG_INTEGER}.make_from_integer64 (i64) + create {BIG_INTEGER}.make_from_integer32 (i32) ~ create {BIG_INTEGER}.make_from_string ("2147483662")
			check
					Result
			end
		end
	
end -- class INT_ADVANCED_TEST

Generated by ISE EiffelStudio