PageRenderTime 7ms CodeModel.GetById 1ms app.highlight 2ms RepoModel.GetById 1ms app.codeStats 0ms

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