"Fossies" - the Fresh Open Source Software Archive

Member "asymptote-2.60/tests/types/keyword.asy" (6 Nov 2019, 4242 Bytes) of package /linux/misc/asymptote-2.60.src.tgz:


As a special service "Fossies" has tried to format the requested text file into HTML format (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file.

    1 import TestLib;
    2 StartTest("keyword");
    3 {
    4   int f(int keyword x) {
    5     return 2*x;
    6   }
    7 
    8   assert(f(x=17) == 34);
    9 }
   10 
   11 {
   12   int f(int keyword x = 10) {
   13     return 2*x;
   14   }
   15 
   16   assert(f() == 20);
   17 }
   18 
   19 {
   20   int f(int keyword x = 10, int keyword y = 20)
   21   {
   22     return 2x+y;
   23   }
   24 
   25   assert(f(x=1,y=2) == 4);
   26   assert(f(y=1,x=2) == 5);
   27   assert(f(x=1) == 22);
   28   assert(f(y=7) == 27);
   29   assert(f() == 40);
   30 }
   31 
   32 {
   33   int f(int keyword x, int keyword y = 20)
   34   {
   35     return x+y;
   36   }
   37 
   38   assert(f(x=1,y=2) == 3);
   39   assert(f(x=1) == 21);
   40 }
   41 
   42 {
   43   int f(int keyword x = 10, int keyword y)
   44   {
   45     return x+y;
   46   }
   47 
   48   assert(f(x=1,y=2) == 3);
   49   assert(f(y=2) == 12);
   50 }
   51 
   52 {
   53   int f(int keyword x, int keyword y)
   54   {
   55     return x+y;
   56   }
   57 
   58   assert(f(x=1,y=2) == 3);
   59 }
   60 
   61 {
   62   int f(int x, int keyword y)
   63   {
   64     return 2x+y;
   65   }
   66 
   67   assert(f(x=1,y=2) == 4);
   68   assert(f(1,y=2) == 4);
   69   assert(f(y=2,1) == 4);
   70   assert(f(y=2,x=1) == 4);
   71 }
   72 
   73 {
   74   int f(... int[] nums, int keyword r)
   75   {
   76     return r;
   77   }
   78 
   79   assert(f(r=3) == 3);
   80   assert(f(1,r=3) == 3);
   81   assert(f(1,2, r=3) == 3);
   82   assert(f(1,2,4,5,6, r=3) == 3);
   83   assert(f(r=3, 10, 20, 30) == 3);
   84   assert(f(4, 5, r=3, 10, 20, 30) == 3);
   85   assert(f(4, 5, r=3, 10, 20, 30 ... new int[] {40,50,60}) == 3);
   86   assert(f(r=3, 10, 20, 30 ... new int[] {40,50,60}) == 3);
   87   assert(f(r=3, 10, 20, 30 ... new int[] {40,50,60}) == 3);
   88   assert(f(... new int[] {40,50,60}, r=3) == 3);
   89   assert(f(... new int[] {40,50,60}, r=3) == 3);
   90 }
   91 
   92 {
   93   int f(... int[] nums, int keyword r=77)
   94   {
   95     return r;
   96   }
   97 
   98   assert(f(r=3) == 3);
   99   assert(f(1,r=3) == 3);
  100   assert(f(1,2, r=3) == 3);
  101   assert(f(1,2,4,5,6, r=3) == 3);
  102   assert(f(r=3, 10, 20, 30) == 3);
  103   assert(f(4, 5, r=3, 10, 20, 30) == 3);
  104   assert(f(4, 5, r=3, 10, 20, 30 ... new int[] {40,50,60}) == 3);
  105   assert(f(r=3, 10, 20, 30 ... new int[] {40,50,60}) == 3);
  106   assert(f(r=3, 10, 20, 30 ... new int[] {40,50,60}) == 3);
  107   assert(f(... new int[] {40,50,60}, r=3) == 3);
  108   assert(f(... new int[] {40,50,60}, r=3) == 3);
  109 
  110   assert(f() == 77);
  111   assert(f(1) == 77);
  112   assert(f(1,2) == 77);
  113   assert(f(1,2,4,5,6) == 77);
  114   assert(f(10, 20, 30) == 77);
  115   assert(f(4, 5, 10, 20, 30) == 77);
  116   assert(f(4, 5, 10, 20, 30 ... new int[] {40,50,60}) == 77);
  117   assert(f(10, 20, 30 ... new int[] {40,50,60}) == 77);
  118   assert(f(10, 20, 30 ... new int[] {40,50,60}) == 77);
  119   assert(f(... new int[] {40,50,60}) == 77);
  120   assert(f(... new int[] {40,50,60}) == 77);
  121 }
  122 
  123 {
  124   int f(int x ... int[] nums, int keyword r=77)
  125   {
  126     return r;
  127   }
  128 
  129   assert(f(345,r=3) == 3);
  130   assert(f(345,1,r=3) == 3);
  131   assert(f(345,1,2, r=3) == 3);
  132   assert(f(345,1,2,4,5,6, r=3) == 3);
  133   assert(f(345,r=3, 10, 20, 30) == 3);
  134   assert(f(345,4, 5, r=3, 10, 20, 30) == 3);
  135   assert(f(345,4, 5, r=3, 10, 20, 30 ... new int[] {40,50,60}) == 3);
  136   assert(f(345,r=3, 10, 20, 30 ... new int[] {40,50,60}) == 3);
  137   assert(f(345,r=3, 10, 20, 30 ... new int[] {40,50,60}) == 3);
  138   assert(f(345 ... new int[] {40,50,60}, r=3) == 3);
  139   assert(f(345 ... new int[] {40,50,60}, r=3) == 3);
  140 
  141   assert(f(345) == 77);
  142   assert(f(345,1) == 77);
  143   assert(f(345,1,2) == 77);
  144   assert(f(345,1,2,4,5,6) == 77);
  145   assert(f(345,10, 20, 30) == 77);
  146   assert(f(345,4, 5, 10, 20, 30) == 77);
  147   assert(f(345,4, 5, 10, 20, 30 ... new int[] {40,50,60}) == 77);
  148   assert(f(345,10, 20, 30 ... new int[] {40,50,60}) == 77);
  149   assert(f(345,10, 20, 30 ... new int[] {40,50,60}) == 77);
  150   assert(f(345 ... new int[] {40,50,60}) == 77);
  151   assert(f(345 ... new int[] {40,50,60}) == 77);
  152 }
  153 
  154 {
  155   int sqr(int x=7) { return x*x; }
  156   int f(int keyword x) = sqr;
  157   int g(int keyword x=666) = sqr;
  158   assert(f(x=5) == 25);
  159   assert(g(x=5) == 25);
  160   assert(g() == 49);
  161 }
  162 {
  163   int sqr(int n=7) { return n*n; }
  164   int f(int keyword x) = sqr;
  165   int g(int keyword x=666) = sqr;
  166   assert(f(x=5) == 25);
  167   assert(g(x=5) == 25);
  168   assert(g() == 49);
  169 }
  170 {
  171   int sqr(int keyword x=7) { return x*x; }
  172   int f(int x) = sqr;
  173   int g(int x=666) = sqr;
  174   assert(f(x=5) == 25);
  175   assert(g(x=5) == 25);
  176   assert(f(5) == 25);
  177   assert(g(5) == 25);
  178   assert(g() == 49);
  179 }
  180 {
  181   int sqr(int keyword n=7) { return n*n; }
  182   int f(int x) = sqr;
  183   int g(int x=666) = sqr;
  184   assert(f(x=5) == 25);
  185   assert(g(x=5) == 25);
  186   assert(f(5) == 25);
  187   assert(g(5) == 25);
  188   assert(g() == 49);
  189 }
  190 EndTest();