Ignore:
Timestamp:
Aug 9, 2024, 8:28:43 AM (4 months ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
master
Children:
16915b1, 6abb6dc
Parents:
f125e96
Message:

update test file covering problem cases

File:
1 edited

Legend:

Unmodified
Added
Removed
  • doc/theses/jiada_liang_MMath/test1.cfa

    rf125e96 r5ca5263  
    11#include <fstream.hfa>                                                                  // sout
    22#include <stdlib.hfa>                                                                   // ato
     3#include <enum.hfa>
    34
    45// integral
     
    910enum( Letter ) Greek { Alph = A, Beta = B, Gamma = G, /* more enums */ Zeta = Z }; // alphabet intersection
    1011
     12// integral
    1113enum( char ) Currency { Dollar = '$', Cent = '¢', Yen = '¥', Pound = '£', Euro = 'E' }; // iso-latin-1
    1214enum( Currency ) Europe { Euro = Currency.Euro, Pound = Currency.Pound };
     
    3335
    3436enum() Mode { O_RDONLY, O_WRONLY, O_CREAT, O_TRUNC, O_APPEND };
    35 Mode iomode = O_RDONLY;
    36 //bool b = iomode == O_RDONLY || iomode < O_APPEND;     // disallowed
    37 //int www = iomode;     // disallowed
     37Mode mode = O_RDONLY;
     38void opaque() {
     39bool b = mode == O_RDONLY || mode < O_APPEND;   // disallowed
     40//int www = mode;       // disallowed
     41}
    3842
    3943enum( char * ) Colour { Red = "red", Green = "green", Blue = "blue"  };
     44
     45enum E1 { A1, B1, C1 = A1, D1 = B1 };
     46enum(float) E2 { A2 = 3.5, B2 = 4.5, C2 = A, D2 = B };
    4047
    4148void fred() {
     
    4552//greek = A;                                                            // disallowed
    4653
    47         for ( Greek l = Alph; posn(l) <= posn(Gamma); l = succ( l ) ) {
     54        for ( Greek l = Alph; posn(l) < posn(Gamma); l = succ( l ) ) {
    4855                printf( "%s %c %d\n", label( l ), value( l ), posn( l ) );
    4956        }
    50         for ( Currency c = Dollar; posn(c) <= posn(Currency.Euro); c = succ( c ) ) {
     57        for ( Currency c = Dollar; posn(c) < posn(Currency.Euro); c = succ( c ) ) {
    5158                printf( "%s %c %d\n", label( c ), value( c ), posn( c ) );
    5259        }
    5360}
    5461
    55 
    56 enum( char * ) Names { Fred = "FRED", Mary = "MARY", Jane = "JANE" };
    57 enum( char * ) Names2 { inline Names, Jack = "JACK", Jill = "JILL" };
    58 enum( char * ) Names3 { inline Names2, Sue = "SUE", Tom = "TOM" };
    59 
     62enum( const char * ) Names { Fred = "FRED", Mary = "MARY", Jane = "JANE" };
     63enum( const char * ) Names2 { inline Names, Jack = "JACK", Jill = "JILL" };
     64enum( const char * ) Names3 { inline Names2, Sue = "SUE", Tom = "TOM" };
     65void bar() {
     66        Names fred = Names.Fred;
     67        (Names2)fred;  (Names3)fred;  (Names3)Names2.Jack;  // cast to super type
     68        Names2 fred2 = fred;  Names3 fred3 = fred2; // assign to super type
     69        const char * name = fred;
     70        Names name = Fred;
     71        sout | name | label( name ) | posn( name ) | value( name );
     72}
    6073void f( Names n ) { sout | "Name" | posn( n ); }
    6174void g( Names2 );
     
    6376void j( char * );
    6477
    65 enum color { red, blue, green };
    66 //color c = 0;
    67 //color c = 1;
    68 color c = 2;
    69 int w = red;
     78enum CColour { Red, Blue, Green };
     79CColour c0 = 0;
     80CColour c1 = 1;
     81CColour c = 2;
     82int w = Red;
     83
     84void coo() {
     85        enum(int) Color { Red, Blue, Green };
     86        Colour c = Red;
     87        sout | countof( Colour ) | Countof( c );
     88//      sout | Countof( Colour );
     89        sout | countof( c );
     90}
    7091
    7192// enum(int) Week ! { Mon, Tue, Wed, Thu = 10, Fri, Sat, Sun };
     
    79100// }
    80101
     102void baz() {
     103        enum(int) Count { First, Second, Third/* = First*/, Fourth/* = Second*/ };
     104        enum CCount { First, Second, Third/* = First*/, Fourth/* = Second*/ };
     105        Count cnt = Second;
     106        CCount ccnt = Second;
     107        if ( cnt < Third ) sout | "less than Third";
     108        if ( cnt ) sout | "XXX";
     109        if ( ccnt ) sout | "YYY";
     110        enum(float) F {WWW = 0.0};
     111        F f;
     112        if ( f ) sout | "FFF";
     113        bool ?!=?( Name n, zero_t ) { sout | "DDD";  return n != Fred; }
     114        Name n = Mary;
     115        if ( n ) sout | "NAME";
     116        choose( cnt ) {
     117                case First: sout | "First";
     118                case Second: sout | "Second";
     119                case Third: sout | "Third";
     120                case Fourth: sout | "Fourth";
     121        }
     122//      for (d; Week) { sout | d; }
     123//      for (p; +~=Planet) { sout | p; }
     124        for ( cx; Count ) { sout | cx | nonl; } sout | nl;
     125        for ( cx; +~= Count ) { sout | cx | nonl; } sout | nl;
     126        for ( cx; -~= Count ) { sout | cx | nonl; } sout | nl;
     127        for ( Count cx = lowerBound();; ) {
     128                sout | cx | nonl;
     129          if ( cx == upperBound() ) break;
     130                cx = succ( cx );
     131        }
     132        sout | nl;
     133}
     134
    81135int main() {
    82136        fred();
    83         Names name = Fred;
     137        Names name = Names.Fred;
    84138//      f( name );
    85139
    86140        int jane_pos = posn( Names.Jane );
    87         char * jane_value = value( Names.Jane );
    88         char * jane_label = label( Names.Jane );
     141        const char * jane_value = value( Names.Jane );
     142        const char * jane_label = label( Names.Jane );
    89143        sout | Names.Jane | posn( Names.Jane) | label( Names.Jane ) | value( Names.Jane );
     144
     145        bar();
     146        baz();
     147        coo();
     148
     149        enum Ex { Ax, Bx, Cx, Nx };
     150        float H1[Nx] = { [Ax] : 3.4, [Bx] : 7.1, [Cx] : 0.01 }; // C
     151//      float H2[Ex] = { [Ax] : 3.4, [Bx] : 7.1, [Cx] : 0.01 }; // CFA
     152
     153        enum(int) E { A = 3 } e = A;
     154        sout | A | label( A ) | posn( A ) | value( A );
     155        sout | e | label( e ) | posn( e ) | value( e );
    90156}
Note: See TracChangeset for help on using the changeset viewer.