Mercurial > projects > orange
annotate tests/Slice.d @ 51:70df72d2299a default tip
Added unit tests for events.
author | Jacob Carlborg <doob@me.com> |
---|---|
date | Sat, 13 Aug 2011 17:06:35 +0200 |
parents | 02dbd18b7fe9 |
children |
rev | line source |
---|---|
40
02dbd18b7fe9
Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
1 /** |
02dbd18b7fe9
Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
2 * Copyright: Copyright (c) 2011 Jacob Carlborg. All rights reserved. |
02dbd18b7fe9
Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
3 * Authors: Jacob Carlborg |
02dbd18b7fe9
Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
4 * Version: Initial created: Aug 6, 2011 |
02dbd18b7fe9
Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
5 * License: $(LINK2 http://www.boost.org/LICENSE_1_0.txt, Boost Software License 1.0) |
02dbd18b7fe9
Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
6 */ |
02dbd18b7fe9
Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
7 module tests.Slice; |
02dbd18b7fe9
Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
8 |
02dbd18b7fe9
Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
9 import orange.core.string; |
02dbd18b7fe9
Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
10 import orange.serialization.Serializer; |
02dbd18b7fe9
Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
11 import orange.serialization.archives.XMLArchive; |
02dbd18b7fe9
Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
12 import orange.test.UnitTester; |
02dbd18b7fe9
Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
13 import tests.Util; |
02dbd18b7fe9
Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
14 |
02dbd18b7fe9
Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
15 Serializer serializer; |
02dbd18b7fe9
Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
16 XMLArchive!(char) archive; |
02dbd18b7fe9
Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
17 |
02dbd18b7fe9
Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
18 class J |
02dbd18b7fe9
Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
19 { |
02dbd18b7fe9
Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
20 int[] firstSource; |
02dbd18b7fe9
Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
21 int[] firstSlice; |
02dbd18b7fe9
Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
22 |
02dbd18b7fe9
Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
23 int[] secondSlice; |
02dbd18b7fe9
Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
24 int[] secondSource; |
02dbd18b7fe9
Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
25 } |
02dbd18b7fe9
Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
26 |
02dbd18b7fe9
Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
27 J j; |
02dbd18b7fe9
Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
28 J jDeserialized; |
02dbd18b7fe9
Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
29 |
02dbd18b7fe9
Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
30 unittest |
02dbd18b7fe9
Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
31 { |
02dbd18b7fe9
Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
32 archive = new XMLArchive!(char); |
02dbd18b7fe9
Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
33 serializer = new Serializer(archive); |
02dbd18b7fe9
Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
34 |
02dbd18b7fe9
Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
35 j = new J; |
02dbd18b7fe9
Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
36 j.firstSource = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9].dup; |
02dbd18b7fe9
Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
37 j.firstSlice = j.firstSource[3 .. 7]; |
02dbd18b7fe9
Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
38 j.secondSource = [10, 11, 12, 13, 14, 15].dup; |
02dbd18b7fe9
Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
39 j.secondSlice = j.secondSource[1 .. 4]; |
02dbd18b7fe9
Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
40 |
02dbd18b7fe9
Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
41 describe("serialize slices") in { |
02dbd18b7fe9
Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
42 it("should return serialized slices") in { |
02dbd18b7fe9
Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
43 serializer.reset(); |
02dbd18b7fe9
Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
44 serializer.serialize(j); |
02dbd18b7fe9
Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
45 |
02dbd18b7fe9
Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
46 assert(archive.data().containsDefaultXmlContent()); |
02dbd18b7fe9
Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
47 assert(archive.data().containsXmlTag("object", `runtimeType="tests.Slice.J" type="J" key="0" id="0"`)); |
02dbd18b7fe9
Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
48 assert(archive.data().containsXmlTag("array", `type="int" length="10" key="firstSource" id="1"`)); |
02dbd18b7fe9
Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
49 |
02dbd18b7fe9
Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
50 assert(archive.data().containsXmlTag("int", `key="0" id="2"`, "0")); |
02dbd18b7fe9
Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
51 assert(archive.data().containsXmlTag("int", `key="1" id="3"`, "1")); |
02dbd18b7fe9
Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
52 assert(archive.data().containsXmlTag("int", `key="2" id="4"`, "2")); |
02dbd18b7fe9
Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
53 assert(archive.data().containsXmlTag("int", `key="3" id="5"`, "3")); |
02dbd18b7fe9
Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
54 assert(archive.data().containsXmlTag("int", `key="4" id="6"`, "4")); |
02dbd18b7fe9
Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
55 assert(archive.data().containsXmlTag("int", `key="5" id="7"`, "5")); |
02dbd18b7fe9
Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
56 assert(archive.data().containsXmlTag("int", `key="6" id="8"`, "6")); |
02dbd18b7fe9
Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
57 assert(archive.data().containsXmlTag("int", `key="7" id="9"`, "7")); |
02dbd18b7fe9
Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
58 assert(archive.data().containsXmlTag("int", `key="8" id="10"`, "8")); |
02dbd18b7fe9
Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
59 assert(archive.data().containsXmlTag("int", `key="9" id="11"`, "9")); |
02dbd18b7fe9
Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
60 |
02dbd18b7fe9
Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
61 version (Tango) |
02dbd18b7fe9
Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
62 { |
02dbd18b7fe9
Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
63 assert(archive.data().containsXmlTag("slice", `key="firstSlice" offset="3" length="4"`, "1")); |
02dbd18b7fe9
Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
64 assert(archive.data().containsXmlTag("slice", `key="secondSlice" offset="1" length="3"`, "21")); |
02dbd18b7fe9
Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
65 } |
02dbd18b7fe9
Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
66 |
02dbd18b7fe9
Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
67 assert(archive.data().containsXmlTag("array", `type="int" length="6" key="secondSource" id="21"`)); |
02dbd18b7fe9
Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
68 |
02dbd18b7fe9
Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
69 assert(archive.data().containsXmlTag("int", `key="0" id="22"`, "10")); |
02dbd18b7fe9
Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
70 assert(archive.data().containsXmlTag("int", `key="1" id="23"`, "11")); |
02dbd18b7fe9
Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
71 assert(archive.data().containsXmlTag("int", `key="2" id="24"`, "12")); |
02dbd18b7fe9
Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
72 assert(archive.data().containsXmlTag("int", `key="3" id="25"`, "13")); |
02dbd18b7fe9
Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
73 assert(archive.data().containsXmlTag("int", `key="4" id="26"`, "14")); |
02dbd18b7fe9
Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
74 assert(archive.data().containsXmlTag("int", `key="5" id="27"`, "15")); |
02dbd18b7fe9
Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
75 }; |
02dbd18b7fe9
Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
76 }; |
02dbd18b7fe9
Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
77 |
02dbd18b7fe9
Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
78 describe("deserialize slices") in { |
02dbd18b7fe9
Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
79 jDeserialized = serializer.deserialize!(J)(archive.untypedData); |
02dbd18b7fe9
Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
80 |
02dbd18b7fe9
Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
81 it("should return deserialized strings equal to the original strings") in { |
02dbd18b7fe9
Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
82 assert(j.firstSource == jDeserialized.firstSource); |
02dbd18b7fe9
Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
83 assert(j.secondSource == jDeserialized.secondSource); |
02dbd18b7fe9
Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
84 }; |
02dbd18b7fe9
Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
85 |
02dbd18b7fe9
Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
86 it("should return deserialized slices equal to the original slices") in { |
02dbd18b7fe9
Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
87 assert(j.firstSlice == jDeserialized.firstSlice); |
02dbd18b7fe9
Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
88 assert(j.secondSlice == jDeserialized.secondSlice); |
02dbd18b7fe9
Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
89 }; |
02dbd18b7fe9
Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
90 |
02dbd18b7fe9
Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
91 it("the slices should be equal to a slice of the original sources") in { |
02dbd18b7fe9
Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
92 assert(jDeserialized.firstSource[3 .. 7] == jDeserialized.firstSlice); |
02dbd18b7fe9
Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
93 assert(jDeserialized.secondSource[1 .. 4] == jDeserialized.secondSlice); |
02dbd18b7fe9
Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
94 |
02dbd18b7fe9
Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
95 assert(j.firstSource[3 .. 7] == jDeserialized.firstSlice); |
02dbd18b7fe9
Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
96 assert(j.secondSource[1 .. 4] == jDeserialized.secondSlice); |
02dbd18b7fe9
Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
97 }; |
02dbd18b7fe9
Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
98 |
02dbd18b7fe9
Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
99 it("the slices should be able to modify the sources") in { |
02dbd18b7fe9
Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
100 jDeserialized.firstSlice[0] = 55; |
02dbd18b7fe9
Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
101 jDeserialized.secondSlice[0] = 3; |
02dbd18b7fe9
Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
102 |
02dbd18b7fe9
Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
103 assert(jDeserialized.firstSource == [0, 1, 2, 55, 4, 5, 6, 7, 8, 9]); |
02dbd18b7fe9
Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
104 assert(jDeserialized.secondSource == [10, 3, 12, 13, 14, 15]); |
02dbd18b7fe9
Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
105 }; |
02dbd18b7fe9
Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
106 }; |
02dbd18b7fe9
Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
107 } |