Newer
Older
zweic / tests / 4 / method00.zwei
@ajaggi ajaggi on 26 Dec 2005 1 KB Added some test cases
  1. // zweic - test program for method typing
  2. // M. Ganguin, J. Ruffin 2005
  3.  
  4. class foo {}
  5. class bar extends foo {}
  6. class baz extends bar {}
  7.  
  8. // Method
  9.  
  10. class MethodTest {
  11. UNKNOWN foo() {} // 1/5 failure of clause 1 (incorrectly typed return type)
  12. Null bar(Int a, Null b, UNKNOWN c) {} // 2/5 failure of clause 1 (incorrectly typed arguments)
  13.  
  14. MethodTest classReturnTest() { // success of clause 2 (containing class as return type)
  15. return this
  16. }
  17. bar overrideTest(bar a, bar b) { return new bar() } // success of clause 3
  18. foo overrideTest(bar a, bar b) { // 3/5 failure of clauses 3 and 4 (return type not subtype of bar)
  19. return new bar()
  20. }
  21. bar overrideTest(baz a, bar b) { // 4/5 failure of clauses 3 and 4 (parameter type not supertype of bar)
  22. return new bar()
  23. }
  24.  
  25. baz overrideTest(foo a, foo b) { // successful override
  26. return new baz() // success (polymorphism)
  27. }
  28.  
  29. Null varScopeTest(Int a, foo f) {
  30. Int b = a; // success of clause 6 (parameter in variable scope)
  31. foo g = f; // success of clause 6 (parameter in variable scope)
  32. MethodTest m = this; // success of clause 6 (this in variable scope)
  33. }
  34.  
  35. bar returnExpressionTypeTest() { return new foo() } // 5/5 failure of clause 7 (expression type not subtype of declared return type)
  36.  
  37. bar returnExpressionTypeTest2() { return new baz() } // success of clause 7
  38.  
  39. }
  40.  
  41. 0