note description: "[ Testing suite for the BIG_INTEGER Class covering the operation capabilities on very large numbers. ]" author: "JSO & CD" date: "June 6 2019" revision: "1.00" class INT_LONG_TEST inherit ES_TEST create make feature {NONE} -- Initialization make do create i1.make_from_string ("75843729058432099845623987849785843902885094382") create i2.make_from_string ("4535438549854903278504932073290054372504865743") create answer.default_create 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 t50) add_boolean_case (agent t51) end feature -- Attributes i1: BIG_INTEGER i2: BIG_INTEGER answer: BIG_INTEGER feature -- Tests t1: BOOLEAN do comment ("t1: Addition - Very Large Integers") answer := create {BIG_INTEGER}.make_from_string ("80379167608287003124128919923075898275389960125") Result := i1 + i2 ~ answer check Result end Result := i1 + i2 ~ create {BIG_INTEGER}.make_from_string ("80379167608287003124128919923075898275389960125") check Result end Result := (i1 + i2).out ~ "80379167608287003124128919923075898275389960125" check Result end end t2: BOOLEAN do comment ("t2: Subtraction - Very Large Integers") answer := create {BIG_INTEGER}.make_from_string ("71308290508577196567119055776495789530380228639") Result := i1 - i2 ~ answer check Result end Result := i1 - i2 ~ create {BIG_INTEGER}.make_from_string ("71308290508577196567119055776495789530380228639") check Result end Result := (i1 - i2).out ~ "71308290508577196567119055776495789530380228639" check Result end answer := create {BIG_INTEGER}.make_from_string ("-71308290508577196567119055776495789530380228639") Result := i2 - i1 ~ answer check Result end Result := i2 - i1 ~ create {BIG_INTEGER}.make_from_string ("-71308290508577196567119055776495789530380228639") check Result end Result := (i2 - i1).out ~ "-71308290508577196567119055776495789530380228639" check Result end end t3: BOOLEAN -- Multiplication do comment ("t3: Multiplication - Very Large Integers") answer := create {BIG_INTEGER}.make_from_string ("343984572536363471764953370510996842545122233740057866577965768795250381398043841122793555826") Result := i1 * i2 ~ answer check Result end Result := i1 * i2 ~ create {BIG_INTEGER}.make_from_string ("343984572536363471764953370510996842545122233740057866577965768795250381398043841122793555826") end t4: BOOLEAN -- Division do comment ("t4: Division - Very Large Integers") answer := create {BIG_INTEGER}.make_from_string ("16") Result := i1 // i2 ~ answer check Result end end t5: BOOLEAN -- Power do comment ("t5: Power - Very Large Integers") answer := create {BIG_INTEGER}.make_from_string ("190334742364607652155107336189619557300746150258796951555022653630312334631543560605738075562813964210570753927595368814050317457233837391456768083319983219297294285812519379516050328960013136910960459963768346105403116172781874416655835066868587540203304953006545312601677853097024") Result := i1.power (6) ~ answer check Result end assert_equal ("fail", (i1.power (6)).out, "190334742364607652155107336189619557300746150258796951555022653630312334631543560605738075562813964210570753927595368814050317457233837391456768083319983219297294285812519379516050328960013136910960459963768346105403116172781874416655835066868587540203304953006545312601677853097024") end t6: BOOLEAN -- Square do comment ("t6: Square - Very Large Integers") answer := create {BIG_INTEGER}.make_from_string ("5752271237488857694599205433125871370720334779334273953877384762094874006286361709193047961924") Result := i1.square ~ answer end t7: BOOLEAN -- Remainder do comment ("t7: Remainder - Very Large Integers") answer := create {BIG_INTEGER}.make_from_string ("3276712260753647389545074677144973942807242494") Result := i1 \\ i2 ~ answer check Result end answer := create {BIG_INTEGER}.make_from_string ("4535438549854903278504932073290054372504865743") Result := i2 \\ i1 ~ answer check Result end end t8: BOOLEAN -- GCD local i3: BIG_INTEGER do comment ("t8: GCD - Very Large Integers") i3 := create {attached BIG_INTEGER}.make_from_string ("37921864529216049922811993924892921951442547191") answer := create {BIG_INTEGER}.make_from_string ("37921864529216049922811993924892921951442547191") Result := i1.gcd (i3) ~ answer end t9: BOOLEAN -- is_string_int local do comment ("t9: is_string_int - Very Large Integers") Result := not i1.is_string_int ("467128642831764315739215904321564239564789+5436218975017540728548726584901709574312075483912574354325432") check Result end Result := i1.is_string_int ("4671286428317643157392159043215642395647895189473129057423189056271876548971205948319058436789") check Result end Result := i1.is_string_int ("000000000000000000000000000000000000004671286428317643157392159043215642395647895189473129057423189056271876548971205948319058436789") check Result end Result := i1.is_string_int ("-4671286428317643157392159043215642395647895189473129057423189056271876548971205948319058436789") check Result end Result := i1.is_string_int ("-000000000000000000000000000000000000004671286428317643157392159043215642395647895189473129057423189056271876548971205948319058436789") check Result end Result := not i1.is_string_int ("+000000000000000000000000000000000000004671286428317643157392159043215642395647895189473129057423189056271876548971205948319058436789") check Result end Result := not i1.is_string_int ("00-000000000000000000000000000000000000004671286428317643157392159043215642395647895189473129057423189056271876548971205948319058436789") check Result end end t10: BOOLEAN local i: BIG_INTEGER do comment ("t10: make and is_equal - Very Large Integers") create i.make_from_string ("9223372036854775808000000000000") check i.out ~ "9223372036854775808000000000000" and i ~ create {BIG_INTEGER}.make_from_string ("9223372036854775808000000000000") end create i.make_from_string ("9223372036854775808000000000001") check i.out ~ "9223372036854775808000000000001" and i ~ create {BIG_INTEGER}.make_from_string ("9223372036854775808000000000001") end create i.make_from_string ("0009223372036854775808000000000001") check i.out ~ "9223372036854775808000000000001" and i ~ create {BIG_INTEGER}.make_from_string ("9223372036854775808000000000001") end create i.make_from_string ("-0009223372036854775808000000000001") check i.out ~ "-9223372036854775808000000000001" and i ~ create {BIG_INTEGER}.make_from_string ("-9223372036854775808000000000001") end Result := i ~ create {BIG_INTEGER}.make_from_string ("-00000000009223372036854775808000000000001") end feature -- very long tests t50: BOOLEAN local x, y, r: BIG_INTEGER do comment ("t50: multiplication of two 1000 digit numbers") x := create {attached BIG_INTEGER}.make_from_string ("2965568378353123276348061266345783080824888634173636635747635072202278707255784767454711192972916696146985661243932638766743001420951575314525858150705284819438425780293854776985371743037095791702583725125451137558376530251552620295919831538359317595569382601550696344356463908920658071820940271591653") y := create {attached BIG_INTEGER}.make_from_string ("4672161668346256276894539982323613161323003926846417075720492380110430364172843882368741633254526841817867620859794648380999526377667612987783332414498121324964878519111977993241729555032137992303648692476480001375176483343253229604747667706893386237386341281432242488415592920241193919031810456388473") r := create {attached BIG_INTEGER}.make_from_string ("13855614902201230205396713838124973760884289654978319485082311142137827087037382261509727150448924026549639848300664275669756587958950101823084182662557603396553772413981330555796120057474978516493072772846480426310778474402862373352861984654437177663375784351271636410526463740967799532494281045773213312922392960285344870223371612383545660065429213425366297503367089113221838868648495159175215200868167451571769566788069803967064303112282810810635542749317601737077412949436378000501858987877504536107186295566967358769555137998905769629206690746812167187647482242005373441714818280697457849792215869") Result := x * y ~ r end t51: BOOLEAN local x, y, z, r: BIG_INTEGER do comment ("t51: division of two 1000 digit numbers") x := create {attached BIG_INTEGER}.make_from_string ("2965568378353123276348061266345783080824888634173636635747635072202278707255784767454711192972916696146985661243932638766743001420951575314525858150705284819438425780293854776985371743037095791702583725125451137558376530251552620295919831538359317595569382601550696344356463908920658071820940271591653") y := create {attached BIG_INTEGER}.make_from_string ("4672161668346256276894539982323613161323003926846417075720492380110430364172843882368741633254526841817867620859794648380999526377667612987783332414498121324964878519111977993241729555032137992303648692476480001375176483343253229604747667706893386237386341281432242488415592920241193919031810456388473") r := create {attached BIG_INTEGER}.make_from_string ("13855614902201230205396713838124973760884289654978319485082311142137827087037382261509727150448924026549639848300664275669756587958950101823084182662557603396553772413981330555796120057474978516493072772846480426310778474402862373352861984654437177663375784351271636410526463740967799532494281045773213312922392960285344870223371612383545660065429213425366297503367089113221838868648495159175215200868167451571769566788069803967064303112282810810635542749317601737077412949436378000501858987877504536107186295566967358769555137998905769629206690746812167187647482242005373441714818280697457849792215869") z := r // y Result := z ~ x end end -- class INT_LONG_TEST
Generated by ISE EiffelStudio