Bu, dersin bir parçasıdır. Bu sınıf, BAG [G -> {HASHABLE, COMPARABLE}] olarak adlandırılır; ADT_BAG'den, sayım, genişletme, çıkarma, kaldırma_sayısı, add_all ... daha fazla ve yeniden uygulanacak alan adı gibi ertelenmiş özelliklere sahip olandan devralınır. GE-posta ile Özel Durum Sonrası İhlaller
sıralanmış bir dizi listesidiralanı döner ARRAY [G]
hep nesne karşılaştırma ile ilgili bir şey olduğunu Sonrası koşul ihlali "value_semantics" olsun ama ben kontrol ve nesne için herhangi bir kod yoktur çok garip olan karşılaştırma.
Etki alanı özelliğinin kodunu birkaç kez yeniden denemeyi denedim ve HER ZAMAN, bir koşul sonrası ihlali veya bir hatayla sona erer.
Ben ayıklayıcısını dizisi "a" her zaman 0 saymak olmuştur etki alanından döndürülen ama tablodan tuşlara taşımak çünkü bu mantıklı değil "bir" ama sayımı hala Belki 0.
olduğunu kontrol zaman Anahtarları diziye yanlış mı gönderiyorum?
kodu:
count: INTEGER
-- cardinality of the domain
do
result := domain.count -- has to be domain.count because loop invariant: consistent: count = domain.count
end
domain: ARRAY[G]
-- sorted domain of bag
local
tmp: G
a: ARRAY[G]
do
create a.make_empty
across 1 |..| (a.count) as i -- MOVING keys from table to array
loop
across table as t
loop
if not a.has (t.key) then
a.enter (t.key, i.item)
i.forth
end
end
end
across 1 |..| (a.count-1) as i -- SORTING
loop
if a[i.item] > a[i.item+1] then
tmp := a[i.item]
a[i.item] := a[i.item+1]
a[i.item+1] := tmp
end
end
Result := a
ensure then
value_semantics: Result.object_comparison -- VIOLATION THROWN HERE
correct_items: across 1 |..| Result.count as j all
has(Result[j.item]) end
sorted: across 1 |..| (Result.count-1) as j all
Result[j.item] <= Result[j.item+1] end
end
Test kodu:
t3: BOOLEAN
local
sorted_domain: ARRAY[STRING]
do
comment("t3:test sorted domain")
sorted_domain := <<"bolts", "hammers", "nuts">>
sorted_domain.compare_objects
Result := bag2.domain ~ sorted_domain -- fails here
check Result end
end