Newer
Older
zweic / tests / 4 / statement00.zwei
@ajaggi ajaggi on 26 Dec 2005 1 KB Added some test cases
  1. // zweic - test program for statement testing
  2. // M. Ganguin, J. Ruffin 2005
  3.  
  4. // While
  5. class WhileTest {
  6. Null foo() {
  7. Int t = 0;
  8. Null n = null;
  9. while(n) {} // 1/2 failure of clause 1 (condition type not Int)
  10. while(t) { Int s = null; } // 2/2 failure of clause 2 (incorrectly typed statement)
  11. while(t) { Int s = 0; } // correct
  12. }
  13. }
  14.  
  15. // Var
  16. class foo {}
  17. class bar extends foo {}
  18. class baz {}
  19. class VarTest {
  20. Null foo() {
  21. Int n = 1;
  22. nonexistent ne = new nonexistent(); // 1/4 failure of clause 1 (nonexistent type)
  23. baz b = new foo(); // 2/4 failure of clause 2 (subtype mismatch)
  24. bar f = new foo(); // 3/4 failure of clause 2 (inverted sub- and supertypes)
  25. Int n = 2; // 4/4 failure of clause 3 (variable n already exists)
  26. Int z = 3; // success
  27. }
  28. }
  29.  
  30. // Set
  31. class SetTest {
  32. Null foo() {
  33. Int n = 1;
  34. bar b = new bar();
  35. s = 2; // 1/3 failure of clause 1 (nonexistent variable)
  36. n = new foo(); // 2/3 failure of clauses 2 and 3 (subtype mismatch)
  37. b = new foo(); // 3/3 failure of clauses 2 and 3 (inverted sub- and supertypes)
  38. b = new bar(); // success
  39. }
  40. }
  41.  
  42. // Do
  43. class DoTest {
  44. Null foo() {
  45. Null k = null;
  46. 2 + k; // 1/1 failure of clause 1 (incorrectly typed expression)
  47. 2 + 2; // success
  48. }
  49. }
  50.  
  51. // PrintInt
  52. class PrintIntTest {
  53. Null foo() {
  54. printInt(new foo()); // 1/1 failure of clause 1 (type must be Int)
  55. printInt(2); //success
  56. }
  57. }
  58.  
  59. // PrintChar
  60. class PrintCharTest {
  61. Null foo() {
  62. printChar(new foo()); // 1/1 failure of clause 1 (type must be Int)
  63. printChar(2); //success
  64. }
  65. }
  66.  
  67. 0