/test/language/agent/test_agent03.e

http://github.com/tybor/Liberty · Specman e · 110 lines · 79 code · 10 blank · 21 comment · 0 complexity · 00d5695e22326151df00c0ec1735f56c MD5 · raw file

  1. -- This file is part of SmartEiffel The GNU Eiffel Compiler Tools and Libraries.
  2. -- See the Copyright notice at the end of this file.
  3. --
  4. class TEST_AGENT03
  5. insert
  6. EIFFELTEST_TOOLS
  7. create {}
  8. make
  9. feature {}
  10. make
  11. local
  12. my_collection: COLLECTION[STRING]; agent1: PROCEDURE[TUPLE]; agent2: FUNCTION[TUPLE[APPLE], STRING]
  13. string: STRING; memo: INTEGER
  14. do
  15. my_collection := {ARRAY[STRING] 1, << "Benedicte", "Lucien", "Marie" >> }
  16. my_collection.for_each(agent print_item1('#', ?))
  17. number := 0
  18. my_collection.for_each(agent print_item1('#', ?))
  19. number := 0
  20. my_collection.for_each(agent print_item2(?))
  21. memo := assert_counter.item
  22. agent1 := agent print3
  23. assert(memo = assert_counter.item)
  24. agent1.call([])
  25. assert(memo = assert_counter.item - 2)
  26. agent2 := agent function2({APPLE})
  27. string := agent2.item([ create {APPLE}])
  28. assert(string.is_equal("APPLE"))
  29. agent2 := agent function2({APPLE})
  30. number := 0
  31. my_collection.for_each(agent (s: STRING) is do assert(s.is_equal(function1(s))) end (?))
  32. assert(number = 3)
  33. assert("foo".is_equal((agent function1(?)).item(["foo"])))
  34. end
  35. function1 (s: STRING): STRING
  36. do
  37. number := number + 1
  38. Result := s
  39. inspect
  40. number
  41. when 1 then
  42. assert(Result.is_equal("Benedicte"))
  43. when 2 then
  44. assert(Result.is_equal("Lucien"))
  45. when 3 then
  46. assert(Result.is_equal("Marie"))
  47. when 4 then
  48. assert(Result.is_equal("foo"))
  49. end
  50. end
  51. function2 (f: FRUIT): STRING
  52. do
  53. Result := f.generator
  54. assert(Result.is_equal("APPLE"))
  55. end
  56. print3
  57. do
  58. assert(True)
  59. end
  60. print_item1 (c: CHARACTER; item: STRING)
  61. require
  62. c /= '%U'
  63. item /= Void
  64. do
  65. assert(c = '#')
  66. number := number + 1
  67. inspect
  68. number
  69. when 1 then
  70. assert(item.is_equal("Benedicte"))
  71. when 2 then
  72. assert(item.is_equal("Lucien"))
  73. when 3 then
  74. assert(item.is_equal("Marie"))
  75. end
  76. end
  77. print_item2 (item: STRING)
  78. do
  79. print_item1('#', item)
  80. end
  81. number: INTEGER
  82. end -- class TEST_AGENT03
  83. --
  84. -- ------------------------------------------------------------------------------------------------------------------------------
  85. -- Copyright notice below. Please read.
  86. --
  87. -- SmartEiffel is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License,
  88. -- as published by the Free Software Foundation; either version 2, or (at your option) any later version.
  89. -- SmartEiffel is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY; without even the implied warranty
  90. -- of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have
  91. -- received a copy of the GNU General Public License along with SmartEiffel; see the file COPYING. If not, write to the Free
  92. -- Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
  93. --
  94. -- Copyright(C) 1994-2002: INRIA - LORIA (INRIA Lorraine) - ESIAL U.H.P. - University of Nancy 1 - FRANCE
  95. -- Copyright(C) 2003-2006: INRIA - LORIA (INRIA Lorraine) - I.U.T. Charlemagne - University of Nancy 2 - FRANCE
  96. --
  97. -- Authors: Dominique COLNET, Philippe RIBET, Cyril ADRIAN, Vincent CROIZIER, Frederic MERIZEN
  98. --
  99. -- http://SmartEiffel.loria.fr - SmartEiffel@loria.fr
  100. -- ------------------------------------------------------------------------------------------------------------------------------