PageRenderTime 23ms CodeModel.GetById 0ms RepoModel.GetById 0ms app.codeStats 0ms

/trunk/Examples/test-suite/octave/overload_template_runme.m

#
MATLAB | 184 lines | 139 code | 45 blank | 0 comment | 39 complexity | 683f1f298ee69e1e8179351f1fa81664 MD5 | raw file
Possible License(s): LGPL-2.1, Cube, GPL-3.0, 0BSD, GPL-2.0
  1. overload_template
  2. f = foo();
  3. a = maximum(3,4);
  4. b = maximum(3.4,5.2);
  5. # mix 1
  6. if (mix1("hi") != 101)
  7. error("mix1(const char*)")
  8. endif
  9. if (mix1(1.0, 1.0) != 102)
  10. error("mix1(double, const double &)")
  11. endif
  12. if (mix1(1.0) != 103)
  13. error("mix1(double)")
  14. endif
  15. # mix 2
  16. if (mix2("hi") != 101)
  17. error("mix2(const char*)")
  18. endif
  19. if (mix2(1.0, 1.0) != 102)
  20. error("mix2(double, const double &)")
  21. endif
  22. if (mix2(1.0) != 103)
  23. error("mix2(double)")
  24. endif
  25. # mix 3
  26. if (mix3("hi") != 101)
  27. error("mix3(const char*)")
  28. endif
  29. if (mix3(1.0, 1.0) != 102)
  30. error("mix3(double, const double &)")
  31. endif
  32. if (mix3(1.0) != 103)
  33. error("mix3(double)")
  34. endif
  35. # Combination 1
  36. if (overtparams1(100) != 10)
  37. error("overtparams1(int)")
  38. endif
  39. if (overtparams1(100.0, 100) != 20)
  40. error("overtparams1(double, int)")
  41. endif
  42. # Combination 2
  43. if (overtparams2(100.0, 100) != 40)
  44. error("overtparams2(double, int)")
  45. endif
  46. # Combination 3
  47. if (overloaded() != 60)
  48. error("overloaded()")
  49. endif
  50. if (overloaded(100.0, 100) != 70)
  51. error("overloaded(double, int)")
  52. endif
  53. # Combination 4
  54. if (overloadedagain("hello") != 80)
  55. error("overloadedagain(const char *)")
  56. endif
  57. if (overloadedagain() != 90)
  58. error("overloadedagain(double)")
  59. endif
  60. # specializations
  61. if (specialization(10) != 202)
  62. error("specialization(int)")
  63. endif
  64. if (specialization(10.1) != 203)
  65. error("specialization(double)")
  66. endif
  67. if (specialization(10, 10) != 204)
  68. error("specialization(int, int)")
  69. endif
  70. if (specialization(10.0, 10.1) != 205)
  71. error("specialization(double, double)")
  72. endif
  73. if (specialization("hi", "hi") != 201)
  74. error("specialization(const char *, const char *)")
  75. endif
  76. # simple specialization
  77. xyz();
  78. xyz_int();
  79. xyz_double();
  80. # a bit of everything
  81. if (overload("hi") != 0)
  82. error("overload()")
  83. endif
  84. if (overload(1) != 10)
  85. error("overload(int t)")
  86. endif
  87. if (overload(1, 1) != 20)
  88. error("overload(int t, const int &)")
  89. endif
  90. if (overload(1, "hello") != 30)
  91. error("overload(int t, const char *)")
  92. endif
  93. k = Klass();
  94. if (overload(k) != 10)
  95. error("overload(Klass t)")
  96. endif
  97. if (overload(k, k) != 20)
  98. error("overload(Klass t, const Klass &)")
  99. endif
  100. if (overload(k, "hello") != 30)
  101. error("overload(Klass t, const char *)")
  102. endif
  103. if (overload(10.1, "hi") != 40)
  104. error("overload(double t, const char *)")
  105. endif
  106. if (overload() != 50)
  107. error("overload(const char *)")
  108. endif
  109. # everything put in a namespace
  110. if (nsoverload("hi") != 1000)
  111. error("nsoverload()")
  112. endif
  113. if (nsoverload(1) != 1010)
  114. error("nsoverload(int t)")
  115. endif
  116. if (nsoverload(1, 1) != 1020)
  117. error("nsoverload(int t, const int &)")
  118. endif
  119. if (nsoverload(1, "hello") != 1030)
  120. error("nsoverload(int t, const char *)")
  121. endif
  122. if (nsoverload(k) != 1010)
  123. error("nsoverload(Klass t)")
  124. endif
  125. if (nsoverload(k, k) != 1020)
  126. error("nsoverload(Klass t, const Klass &)")
  127. endif
  128. if (nsoverload(k, "hello") != 1030)
  129. error("nsoverload(Klass t, const char *)")
  130. endif
  131. if (nsoverload(10.1, "hi") != 1040)
  132. error("nsoverload(double t, const char *)")
  133. endif
  134. if (nsoverload() != 1050)
  135. error("nsoverload(const char *)")
  136. endif
  137. A_foo(1);
  138. b = B();
  139. b.foo(1);