Changeset e8b3717 for tests


Ignore:
Timestamp:
Jan 18, 2024, 10:17:21 PM (14 months ago)
Author:
Michael Brooks <mlbrooks@…>
Branches:
master
Children:
f988834
Parents:
906d8fa
Message:

Modify substring interface from start-end to start-len, and add a missing test.

Location:
tests/collections
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • TabularUnified tests/collections/.expect/string-api-coverage.txt

    r906d8fa re8b3717  
    5151QQQ
    5252asdfasdfasdf
     53lo
     54hello heliocentric
    5355e
    5456help!!!o
  • TabularUnified tests/collections/string-api-coverage.cfa

    r906d8fa re8b3717  
    5151    sout | (s == "hello") | (s == "world");
    5252    sout | (s != "world") | (s != "hello");
    53     sout | ( frag == s(1,4) ) | ( s3   == s(1,4) );
    54     sout | ( s3   != s(1,4) ) | ( frag != s(1,4) );
    55     sout | ( s2(1,4) == s(1,4) ) | ( s3(1,4)   == s(1,4) );
    56     sout | ( s3(1,4) != s(1,4) ) | ( s2(1,4)   != s(1,4) );
    57     sout | ( s(1,4) == frag ) | ( s(1,4) == s3   );
    58     sout | ( s(1,4) != s3   ) | ( s(1,4) != frag );
    59     sout | ( s(1,4) == "ell"   ) | ( s(1,4) == "world" );
    60     sout | ( s(1,4) != "world" ) | ( s(1,4) != "ell"   );
     53    sout | ( frag == s(1,3) ) | ( s3   == s(1,3) );
     54    sout | ( s3   != s(1,3) ) | ( frag != s(1,3) );
     55    sout | ( s2(1,3) == s(1,3) ) | ( s3(1,3)   == s(1,3) );
     56    sout | ( s3(1,3) != s(1,3) ) | ( s2(1,3)   != s(1,3) );
     57    sout | ( s(1,3) == frag ) | ( s(1,3) == s3   );
     58    sout | ( s(1,3) != s3   ) | ( s(1,3) != frag );
     59    sout | ( s(1,3) == "ell"   ) | ( s(1,3) == "world" );
     60    sout | ( s(1,3) != "world" ) | ( s(1,3) != "ell"   );
    6161
    6262
     
    226226    //
    227227
    228     //...
     228    // Range cases treated thoroughly in "string-overwrite" test.
     229    // Composability with comparison and search are demoed above and below.
     230    // Coverage here adds the single-argument ("rest of string") overload.
     231
     232    sx = s;
     233    sout | sx(3); // lo
     234    sx(3) = "iocentric";
     235    sout | s | sx; // hello heliocentric
    229236
    230237    //
     
    328335        | find( alphabet        , "def")  // 3
    329336        | find( alphabet( 0, 26), "def")  // 3
    330         | find( alphabet( 2, 26), "def")  // 1
    331         | find( alphabet( 3, 26), "def")  // 0
    332         | find( alphabet( 4, 26), "def")  // 22, not found
    333         | find( alphabet( 4, 26),  "ef")  // 0
     337        | find( alphabet( 2, 24), "def")  // 1
     338        | find( alphabet( 3, 23), "def")  // 0
     339        | find( alphabet( 4, 22), "def")  // 22, not found
     340        | find( alphabet( 4, 22),  "ef")  // 0
    334341        | find( alphabet( 0,  6), "def")  // 3
    335342        | find( alphabet( 0,  5), "def")  // 5, not found
     
    339346        | includes( alphabet        , "def")  // true
    340347        | includes( alphabet( 0, 26), "def")  // true
    341         | includes( alphabet( 2, 26), "def")  // true
    342         | includes( alphabet( 3, 26), "def")  // true
    343         | includes( alphabet( 4, 26), "def")  // false
    344         | includes( alphabet( 4, 26),  "ef")  // true
     348        | includes( alphabet( 2, 24), "def")  // true
     349        | includes( alphabet( 3, 23), "def")  // true
     350        | includes( alphabet( 4, 22), "def")  // false
     351        | includes( alphabet( 4, 22),  "ef")  // true
    345352        | includes( alphabet( 0,  6), "def")  // true
    346353        | includes( alphabet( 0,  5), "def")  // false
     
    350357        | startsWith( alphabet        , "abc")  // true
    351358        | startsWith( alphabet( 0, 26), "abc")  // true
    352         | startsWith( alphabet( 1, 26), "abc")  // false
    353         | startsWith( alphabet( 1, 26),  "bc")  // true
     359        | startsWith( alphabet( 1, 25), "abc")  // false
     360        | startsWith( alphabet( 1, 25),  "bc")  // true
    354361        | startsWith( alphabet( 0, 26), "abc")  // true
    355362        | startsWith( alphabet( 0,  4), "abc")  // true
     
    365372        | endsWith( alphabet( 0, 25), "xy" )  // true
    366373        | endsWith( alphabet( 0, 26), "xyz")  // true
    367         | endsWith( alphabet(23, 26), "xyz")  // true
    368         | endsWith( alphabet(24, 26), "xyz")  // false
    369         | endsWith( alphabet(24, 26),  "yz")  // true
     374        | endsWith( alphabet(23,  3), "xyz")  // true
     375        | endsWith( alphabet(24,  2), "xyz")  // false
     376        | endsWith( alphabet(24,  2),  "yz")  // true
    370377        | endsWith( alphabet        , "abc"); // false
    371378
  • TabularUnified tests/collections/string-overwrite.cfa

    r906d8fa re8b3717  
    99MS = modifier start
    1010ME = modifier end
     11ML = modifier length
    1112WS = witness start
    1213WE = witness end
     14WL = witness length
    1315
    1416The test does:
     
    7173
    7274
    73 void showOneReplacement(string & s, int ms, int me, int ws, int we, const char* replaceWith) {
     75void showOneReplacement(string & s, int ms, int ml, int ws, int wl, const char* replaceWith) {
     76
     77    int me = ms + ml;
     78    int we = ws + wl;
    7479
    7580    assert( ms >= 0 && ms <= me && me <= size(s) );
    7681    assert( ws >= 0 && ws <= we && we <= size(s) );
    7782
    78     string mod = s(ms, me)`shareEdits;
    79     string wit = s(ws, we)`shareEdits;
     83    string mod = s(ms, ml)`shareEdits;
     84    string wit = s(ws, wl)`shareEdits;
    8085
    8186    string modOld = mod;
     
    118123void runReplaceCases() {
    119124    char * alphabetTemplate = "abcdefghijklmnopqrstuvwxyz";
    120     struct { int ms; int me; int ws; int we; char *replaceWith; char *label; } cases[] = {
    121         { 12, 14, 10, 20, "xxxxx", "warmup" },
    122         { 10, 10, 10, 10, "=====", "1"      },
    123         { 10, 10, 10, 10, "=="   , ""       },
    124         { 10, 10, 10, 10, "="    , ""       },
    125         { 10, 10, 10, 10, ""     , ""       },
    126         { 10, 12, 12, 12, "=====", "2"      },
    127         { 10, 12, 12, 12, "=="   , ""       },
    128         { 10, 12, 12, 12, "="    , ""       },
    129         { 10, 12, 12, 12, ""     , ""       },
    130         { 12, 12, 10, 12, "=====", "3"      },
    131         { 12, 12, 10, 12, "=="   , ""       },
    132         { 12, 12, 10, 12, "="    , ""       },
    133         { 12, 12, 10, 12, ""     , ""       },
    134         { 10, 10, 12, 12, "=====", "4"      },
    135         { 10, 10, 12, 12, "=="   , ""       },
    136         { 10, 10, 12, 12, "="    , ""       },
    137         { 10, 10, 12, 12, ""     , ""       },
    138         { 12, 12, 10, 10, "=====", "5"      },
    139         { 12, 12, 10, 10, "=="   , ""       },
    140         { 12, 12, 10, 10, "="    , ""       },
    141         { 12, 12, 10, 10, ""     , ""       },
    142         { 10, 12, 10, 12, "=====", "6"      },
    143         { 10, 12, 10, 12, "=="   , ""       },
    144         { 10, 12, 10, 12, "="    , ""       },
    145         { 10, 12, 10, 12, ""     , ""       },
    146         { 10, 12, 10, 10, "=====", "7"      },
    147         { 10, 12, 10, 10, "=="   , ""       },
    148         { 10, 12, 10, 10, "="    , ""       },
    149         { 10, 12, 10, 10, ""     , ""       },
    150         { 10, 10, 10, 12, "=====", "8"      },
    151         { 10, 10, 10, 12, "=="   , ""       },
    152         { 10, 10, 10, 12, "="    , ""       },
    153         { 10, 10, 10, 12, ""     , ""       },
    154         { 10, 12, 14, 14, "=====", "9"      },
    155         { 10, 12, 14, 14, "=="   , ""       },
    156         { 10, 12, 14, 14, "="    , ""       },
    157         { 10, 12, 14, 14, ""     , ""       },
    158         { 10, 14, 12, 14, "=====", "10"     },
    159         { 10, 14, 12, 14, "=="   , ""       },
    160         { 10, 14, 12, 14, "="    , ""       },  // FORMERLY unrunnable bug: tries to print seemingly infinite string
    161         { 10, 14, 12, 14, ""     , ""       },  // ditto
    162         { 14, 14, 10, 12, "=====", "11"     },
    163         { 14, 14, 10, 12, "=="   , ""       },
    164         { 14, 14, 10, 12, "="    , ""       },
    165         { 14, 14, 10, 12, ""     , ""       },
    166         { 12, 14, 10, 14, "=====", "12"     }, // correctness observation:  watching klmn while mn |-> xxx gives klxxx because the mn is inside what I'm watching
    167         { 12, 14, 10, 14, "=="   , ""       },
    168         { 12, 14, 10, 14, "="    , ""       },
    169         { 12, 14, 10, 14, ""     , ""       },
    170         { 10, 12, 12, 14, "=====", "13"     },
    171         { 10, 12, 12, 14, "=="   , ""       },
    172         { 10, 12, 12, 14, "="    , ""       },
    173         { 10, 12, 12, 14, ""     , ""       },
    174         { 10, 14, 12, 12, "=====", "14"     },
    175         { 10, 14, 12, 12, "=="   , ""       },
    176         { 10, 14, 12, 12, "="    , ""       },
    177         { 10, 14, 12, 12, ""     , ""       },
    178         { 12, 14, 10, 12, "=====", "15"     },
    179         { 12, 14, 10, 12, "=="   , ""       },
    180         { 12, 14, 10, 12, "="    , ""       },
    181         { 12, 14, 10, 12, ""     , ""       },
    182         { 12, 12, 10, 14, "=====", "16"     },
    183         { 12, 12, 10, 14, "=="   , ""       },
    184         { 12, 12, 10, 14, "="    , ""       },
    185         { 12, 12, 10, 14, ""     , ""       },
    186         { 10, 14, 10, 12, "=====", "17"     },
    187         { 10, 14, 10, 12, "=="   , ""       },
    188         { 10, 14, 10, 12, "="    , ""       },
    189         { 10, 14, 10, 12, ""     , ""       },
    190         { 10, 10, 12, 14, "=====", "18"     },
    191         { 10, 10, 12, 14, "=="   , ""       },
    192         { 10, 10, 12, 14, "="    , ""       },
    193         { 10, 10, 12, 14, ""     , ""       },
    194         { 10, 12, 10, 14, "=====", "19"     },
    195         { 10, 12, 10, 14, "=="   , ""       },
    196         { 10, 12, 10, 14, "="    , ""       },
    197         { 10, 12, 10, 14, ""     , ""       },
    198         { 12, 14, 10, 10, "=====", "20"     },
    199         { 12, 14, 10, 10, "=="   , ""       },
    200         { 12, 14, 10, 10, "="    , ""       },
    201         { 12, 14, 10, 10, ""     , ""       },
    202         { 10, 12, 14, 16, "=====", "21"     },
    203         { 10, 12, 14, 16, "=="   , ""       },
    204         { 10, 12, 14, 16, "="    , ""       },
    205         { 10, 12, 14, 16, ""     , ""       },
    206         { 10, 14, 12, 16, "=====", "22"     },
    207         { 10, 14, 12, 16, "=="   , ""       },
    208         { 10, 14, 12, 16, "="    , ""       },
    209         { 10, 14, 12, 16, ""     , ""       },
    210         { 10, 16, 12, 14, "=====", "23"     },
    211         { 10, 16, 12, 14, "=="   , ""       },
    212         { 10, 16, 12, 14, "="    , ""       },
    213         { 10, 16, 12, 14, ""     , ""       },
    214         { 14, 16, 10, 12, "=====", "24"     },
    215         { 14, 16, 10, 12, "=="   , ""       },
    216         { 14, 16, 10, 12, "="    , ""       },
    217         { 14, 16, 10, 12, ""     , ""       },
    218         { 12, 16, 10, 14, "=====", "25"     },
    219         { 12, 16, 10, 14, "=="   , ""       },
    220         { 12, 16, 10, 14, "="    , ""       },
    221         { 12, 16, 10, 14, ""     , ""       },
    222         { 12, 14, 10, 16, "=====", "26"     },
    223         { 12, 14, 10, 16, "=="   , ""       },
    224         { 12, 14, 10, 16, "="    , ""       },
    225         { 12, 14, 10, 16, ""     , ""       },
     125    struct { int ms; int ml; int ws; int wl; char *replaceWith; char *label; } cases[] = {
     126        { 12,  2, 10, 10, "xxxxx", "warmup" },
     127        { 10,  0, 10,  0, "=====", "1"      },
     128        { 10,  0, 10,  0, "=="   , ""       },
     129        { 10,  0, 10,  0, "="    , ""       },
     130        { 10,  0, 10,  0, ""     , ""       },
     131        { 10,  2, 12,  0, "=====", "2"      },
     132        { 10,  2, 12,  0, "=="   , ""       },
     133        { 10,  2, 12,  0, "="    , ""       },
     134        { 10,  2, 12,  0, ""     , ""       },
     135        { 12,  0, 10,  2, "=====", "3"      },
     136        { 12,  0, 10,  2, "=="   , ""       },
     137        { 12,  0, 10,  2, "="    , ""       },
     138        { 12,  0, 10,  2, ""     , ""       },
     139        { 10,  0, 12,  0, "=====", "4"      },
     140        { 10,  0, 12,  0, "=="   , ""       },
     141        { 10,  0, 12,  0, "="    , ""       },
     142        { 10,  0, 12,  0, ""     , ""       },
     143        { 12,  0, 10,  0, "=====", "5"      },
     144        { 12,  0, 10,  0, "=="   , ""       },
     145        { 12,  0, 10,  0, "="    , ""       },
     146        { 12,  0, 10,  0, ""     , ""       },
     147        { 10,  2, 10,  2, "=====", "6"      },
     148        { 10,  2, 10,  2, "=="   , ""       },
     149        { 10,  2, 10,  2, "="    , ""       },
     150        { 10,  2, 10,  2, ""     , ""       },
     151        { 10,  2, 10,  0, "=====", "7"      },
     152        { 10,  2, 10,  0, "=="   , ""       },
     153        { 10,  2, 10,  0, "="    , ""       },
     154        { 10,  2, 10,  0, ""     , ""       },
     155        { 10,  0, 10,  2, "=====", "8"      },
     156        { 10,  0, 10,  2, "=="   , ""       },
     157        { 10,  0, 10,  2, "="    , ""       },
     158        { 10,  0, 10,  2, ""     , ""       },
     159        { 10,  2, 14,  0, "=====", "9"      },
     160        { 10,  2, 14,  0, "=="   , ""       },
     161        { 10,  2, 14,  0, "="    , ""       },
     162        { 10,  2, 14,  0, ""     , ""       },
     163        { 10,  4, 12,  2, "=====", "10"     },
     164        { 10,  4, 12,  2, "=="   , ""       },
     165        { 10,  4, 12,  2, "="    , ""       },  // FORMERLY unrunnable bug: tries to print seemingly infinite string
     166        { 10,  4, 12,  2, ""     , ""       },  // ditto
     167        { 14,  0, 10,  2, "=====", "11"     },
     168        { 14,  0, 10,  2, "=="   , ""       },
     169        { 14,  0, 10,  2, "="    , ""       },
     170        { 14,  0, 10,  2, ""     , ""       },
     171        { 12,  2, 10,  4, "=====", "12"     }, // correctness observation:  watching klmn while mn |-> xxx gives klxxx because the mn is inside what I'm watching
     172        { 12,  2, 10,  4, "=="   , ""       },
     173        { 12,  2, 10,  4, "="    , ""       },
     174        { 12,  2, 10,  4, ""     , ""       },
     175        { 10,  2, 12,  2, "=====", "13"     },
     176        { 10,  2, 12,  2, "=="   , ""       },
     177        { 10,  2, 12,  2, "="    , ""       },
     178        { 10,  2, 12,  2, ""     , ""       },
     179        { 10,  4, 12,  0, "=====", "14"     },
     180        { 10,  4, 12,  0, "=="   , ""       },
     181        { 10,  4, 12,  0, "="    , ""       },
     182        { 10,  4, 12,  0, ""     , ""       },
     183        { 12,  2, 10,  2, "=====", "15"     },
     184        { 12,  2, 10,  2, "=="   , ""       },
     185        { 12,  2, 10,  2, "="    , ""       },
     186        { 12,  2, 10,  2, ""     , ""       },
     187        { 12,  0, 10,  4, "=====", "16"     },
     188        { 12,  0, 10,  4, "=="   , ""       },
     189        { 12,  0, 10,  4, "="    , ""       },
     190        { 12,  0, 10,  4, ""     , ""       },
     191        { 10,  4, 10,  2, "=====", "17"     },
     192        { 10,  4, 10,  2, "=="   , ""       },
     193        { 10,  4, 10,  2, "="    , ""       },
     194        { 10,  4, 10,  2, ""     , ""       },
     195        { 10,  0, 12,  2, "=====", "18"     },
     196        { 10,  0, 12,  2, "=="   , ""       },
     197        { 10,  0, 12,  2, "="    , ""       },
     198        { 10,  0, 12,  2, ""     , ""       },
     199        { 10,  2, 10,  4, "=====", "19"     },
     200        { 10,  2, 10,  4, "=="   , ""       },
     201        { 10,  2, 10,  4, "="    , ""       },
     202        { 10,  2, 10,  4, ""     , ""       },
     203        { 12,  2, 10,  0, "=====", "20"     },
     204        { 12,  2, 10,  0, "=="   , ""       },
     205        { 12,  2, 10,  0, "="    , ""       },
     206        { 12,  2, 10,  0, ""     , ""       },
     207        { 10,  2, 14,  2, "=====", "21"     },
     208        { 10,  2, 14,  2, "=="   , ""       },
     209        { 10,  2, 14,  2, "="    , ""       },
     210        { 10,  2, 14,  2, ""     , ""       },
     211        { 10,  4, 12,  4, "=====", "22"     },
     212        { 10,  4, 12,  4, "=="   , ""       },
     213        { 10,  4, 12,  4, "="    , ""       },
     214        { 10,  4, 12,  4, ""     , ""       },
     215        { 10,  6, 12,  2, "=====", "23"     },
     216        { 10,  6, 12,  2, "=="   , ""       },
     217        { 10,  6, 12,  2, "="    , ""       },
     218        { 10,  6, 12,  2, ""     , ""       },
     219        { 14,  2, 10,  2, "=====", "24"     },
     220        { 14,  2, 10,  2, "=="   , ""       },
     221        { 14,  2, 10,  2, "="    , ""       },
     222        { 14,  2, 10,  2, ""     , ""       },
     223        { 12,  4, 10,  4, "=====", "25"     },
     224        { 12,  4, 10,  4, "=="   , ""       },
     225        { 12,  4, 10,  4, "="    , ""       },
     226        { 12,  4, 10,  4, ""     , ""       },
     227        { 12,  2, 10,  6, "=====", "26"     },
     228        { 12,  2, 10,  6, "=="   , ""       },
     229        { 12,  2, 10,  6, "="    , ""       },
     230        { 12,  2, 10,  6, ""     , ""       },
    226231    };
    227232    for ( i; sizeof(cases)/sizeof(cases[0]) ) {
    228233        sout | "------------------------------------------------------------------------" | cases[i].label;
    229234        string replaceIn = alphabetTemplate;
    230         showOneReplacement( replaceIn, cases[i].ms, cases[i].me, cases[i].ws, cases[i].we, cases[i].replaceWith );
     235        showOneReplacement( replaceIn, cases[i].ms, cases[i].ml, cases[i].ws, cases[i].wl, cases[i].replaceWith );
    231236    }
    232237}
     
    244249    string s = "abcdefghijklmnopqrstuvwxyz";
    245250
    246     s(5,10) = "qqqqq";  // start=5, end=10, len=5
    247 
    248     sout | s;
    249 
    250 
    251     s(5,5) = "-----";  // start=5, end=5, len=0
     251    s(5,5) = "qqqqq";  // start=5, end=10, len=5
     252
     253    sout | s;
     254
     255
     256    s(5,0) = "-----";  // start=5, end=5, len=0
    252257
    253258    sout | s;
Note: See TracChangeset for help on using the changeset viewer.