/test/lib/storage/dictionary/dictionary_tester.e
Specman e | 205 lines | 153 code | 29 blank | 23 comment | 0 complexity | 74a793a1c7e2bcfac79be72cb1d4eb8d 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 DICTIONARY_TESTER[V_, K_] 5 6inherit 7 DICTIONARY[V_, K_] 8 9insert 10 EIFFELTEST_TOOLS 11 undefine copy, is_equal 12 end 13 14create {ANY} 15 test 16 17feature {ANY} 18 reference_at (k: K_): V_ 19 do 20 Result := tested.reference_at(k) 21 assert(Result = ref.reference_at(k)) 22 end 23 24 fast_reference_at (k: K_): V_ 25 do 26 Result := tested.fast_reference_at(k) 27 assert(Result = ref.fast_reference_at(k)) 28 end 29 30 internal_key (k: K_): K_ 31 do 32 Result := tested.internal_key(k) 33 assert(Result = ref.internal_key(k)) 34 end 35 36 add (v: V_; k: K_) 37 do 38 tested.add(v, k) 39 ref.add(v, k) 40 same_dictionaries 41 end 42 43 fast_has (k: K_): BOOLEAN 44 do 45 Result := tested.fast_has(k) 46 assert(Result = ref.fast_has(k)) 47 end 48 49 has (k: K_): BOOLEAN 50 do 51 Result := tested.has(k) 52 assert(Result = ref.has(k)) 53 end 54 55 remove (k: K_) 56 do 57 tested.remove(k) 58 ref.remove(k) 59 same_dictionaries 60 end 61 62 clear_count 63 do 64 tested.clear_count 65 ref.clear_count 66 same_dictionaries 67 end 68 69 clear_count_and_capacity 70 do 71 tested.clear_count_and_capacity 72 ref.clear_count_and_capacity 73 same_dictionaries 74 end 75 76 capacity: INTEGER 77 do 78 Result := tested.capacity.min(ref.capacity) 79 end 80 81 fast_at (k: K_): V_ 82 do 83 Result := tested.fast_at(k) 84 assert(Result = ref.fast_at(k)) 85 end 86 87 fast_remove (k: K_) 88 do 89 tested.fast_remove(k) 90 ref.fast_remove(k) 91 same_dictionaries 92 end 93 94 item (i: INTEGER): V_ 95 do 96 Result := tested.item(i) 97 -- No assertion here 98 end 99 100 fast_put (v: V_; k: K_) 101 do 102 tested.fast_put(v, k) 103 ref.fast_put(v, k) 104 same_dictionaries 105 end 106 107 put (v: V_; k: K_) 108 do 109 tested.put(v, k) 110 ref.put(v, k) 111 same_dictionaries 112 end 113 114 at (k: K_): V_ 115 do 116 Result := tested.at(k) 117 assert(Result = ref.at(k)) 118 end 119 120 key (i: INTEGER): K_ 121 do 122 Result := tested.key(i) 123 -- No assertion here 124 end 125 126 count: INTEGER 127 do 128 Result := tested.count 129 assert(Result = ref.count) 130 end 131 132 get_new_iterator_on_keys: ITERATOR[K_] 133 do 134 create {ITERATOR_ON_DICTIONARY_KEYS[V_, K_]} Result.make(Current) 135 end 136 137feature {} 138 make 139 do 140 clear_count 141 end 142 143 test (tested_: like tested) 144 local 145 i: INTEGER 146 do 147 tested := tested_ 148 create ref.with_capacity(tested.capacity) 149 from 150 i := tested.lower 151 until 152 i > tested.upper 153 loop 154 ref.put(tested.item(i), tested.key(i)) 155 i := i + 1 156 end 157 end 158 159 same_dictionaries 160 do 161 included_in(ref, tested) 162 included_in(tested, ref) 163 end 164 165 included_in (a, b: DICTIONARY[V_, K_]) 166 local 167 i: INTEGER; v: V_; k: K_ 168 do 169 assert(a.count = b.count) 170 from 171 i := a.lower 172 until 173 i > a.upper 174 loop 175 v := a.item(i) 176 k := a.key(i) 177 assert(b.fast_has(k)) 178 assert(b.fast_at(k) = v) 179 i := i + 1 180 end 181 end 182 183 ref: ARRAY_DICTIONARY[V_, K_] 184 185 tested: DICTIONARY[V_, K_] 186 187end -- class DICTIONARY_TESTER 188-- 189-- ------------------------------------------------------------------------------------------------------------------------------ 190-- Copyright notice below. Please read. 191-- 192-- SmartEiffel is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, 193-- as published by the Free Software Foundation; either version 2, or (at your option) any later version. 194-- SmartEiffel is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY; without even the implied warranty 195-- of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have 196-- received a copy of the GNU General Public License along with SmartEiffel; see the file COPYING. If not, write to the Free 197-- Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. 198-- 199-- Copyright(C) 1994-2002: INRIA - LORIA (INRIA Lorraine) - ESIAL U.H.P. - University of Nancy 1 - FRANCE 200-- Copyright(C) 2003-2006: INRIA - LORIA (INRIA Lorraine) - I.U.T. Charlemagne - University of Nancy 2 - FRANCE 201-- 202-- Authors: Dominique COLNET, Philippe RIBET, Cyril ADRIAN, Vincent CROIZIER, Frederic MERIZEN 203-- 204-- http://SmartEiffel.loria.fr - SmartEiffel@loria.fr 205-- ------------------------------------------------------------------------------------------------------------------------------