Changeset f00b2c2c for tests/rational.cfa
 Timestamp:
 Feb 9, 2020, 8:56:01 AM (4 years ago)
 Branches:
 ADT, armeh, astexperimental, enum, forallpointerdecay, jacob/cs343translation, jenkinssandbox, master, newast, newastuniqueexpr, pthreademulation, qualifiedEnum
 Children:
 d231700
 Parents:
 8c9da33
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

tests/rational.cfa
r8c9da33 rf00b2c2c 10 10 // Created On : Mon Mar 28 08:43:12 2016 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Wed Mar 27 07:37:17 201913 // Update Count : 8 012 // Last Modified On : Sat Feb 8 18:46:23 2020 13 // Update Count : 86 14 14 // 15 15 … … 19 19 #include <fstream.hfa> 20 20 21 double convert( int i ) { return (double)i; } 21 typedef Rational(int) RatInt; 22 double convert( int i ) { return (double)i; } // used by narrow/widen 22 23 int convert( double d ) { return (int)d; } 23 24 24 25 int main() { 25 26 sout  "constructor"; 26 Rat ional(int) a = { 3 }, b = { 4 }, c;27 sout  a  b  c ;27 RatInt a = { 3 }, b = { 4 }, c, d = 0, e = 1; 28 sout  a  b  c  d  e; 28 29 29 a = (Rat ional(int)){ 4, 8 };30 b = (Rat ional(int)){ 5, 7 };30 a = (RatInt){ 4, 8 }; 31 b = (RatInt){ 5, 7 }; 31 32 sout  a  b; 32 a = (Rat ional(int)){ 2, 3 };33 b = (Rat ional(int)){ 3, 2 };33 a = (RatInt){ 2, 3 }; 34 b = (RatInt){ 3, 2 }; 34 35 sout  a  b; 35 a = (Rat ional(int)){ 2, 3 };36 b = (Rat ional(int)){ 3, 2 };36 a = (RatInt){ 2, 3 }; 37 b = (RatInt){ 3, 2 }; 37 38 sout  a  b; 38 39 39 40 sout  "logical"; 40 a = (Rat ional(int)){ 2 };41 b = (Rat ional(int)){ 3, 2 };41 a = (RatInt){ 2 }; 42 b = (RatInt){ 3, 2 }; 42 43 sout  a  b; 43 44 // sout  a == 1; // FIX ME … … 58 59 59 60 sout  "conversion"; 60 a = (Rat ional(int)){ 3, 4 };61 a = (RatInt){ 3, 4 }; 61 62 sout  widen( a ); 62 a = (Rat ional(int)){ 1, 7 };63 a = (RatInt){ 1, 7 }; 63 64 sout  widen( a ); 64 a = (Rat ional(int)){ 355, 113 };65 a = (RatInt){ 355, 113 }; 65 66 sout  widen( a ); 66 67 sout  narrow( 0.75, 4 ); … … 74 75 75 76 sout  "more tests"; 76 Rat ional(int)x = { 1, 2 }, y = { 2 };77 RatInt x = { 1, 2 }, y = { 2 }; 77 78 sout  x  y; 78 79 sout  x > y; … … 80 81 sout  y  denominator( y, 2 )  y; 81 82 82 Rat ional(int)z = { 0, 5 };83 RatInt z = { 0, 5 }; 83 84 sout  z; 84 85 85 86 sout  x  numerator( x, 0 )  x; 86 87 87 x = (Rat ional(int)){ 1, MAX } + (Rational(int)){ 1, MAX };88 x = (RatInt){ 1, MAX } + (RatInt){ 1, MAX }; 88 89 sout  x; 89 x = (Rat ional(int)){ 3, MAX } + (Rational(int)){ 2, MAX };90 x = (RatInt){ 3, MAX } + (RatInt){ 2, MAX }; 90 91 sout  x; 91 92
Note: See TracChangeset
for help on using the changeset viewer.