-
Notifications
You must be signed in to change notification settings - Fork 2
/
qtconceptmapcommandsetconcept_test.cpp
162 lines (133 loc) · 4.64 KB
/
qtconceptmapcommandsetconcept_test.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
#include "qtconceptmapcommandsetconcept_test.h"
#include <iostream>
#include <QDebug>
#include "conceptmapconcept.h"
#include "qtconceptmapcommandsetconcept.h"
#include "qtconceptmap.h"
#include "qtconceptmapcommandcreatenewedge.h"
#include "qtconceptmapcommandcreatenewnode.h"
#include "qtconceptmapqtedge.h"
#include "qtconceptmapqtnode.h"
#include "conceptmapfactory.h"
void ribi::cmap::QtCommandSetConceptTest::FailsOnCenterNode() const noexcept
{
QtConceptMap q;
q.SetConceptMap(ConceptMapFactory().GetLonelyCenterNode());
q.show();
assert(CountSelectedQtNodes(q) == 0);
try
{
q.DoCommand(new CommandSetConcept(q, Concept()));
assert(!"Should not get here");
}
catch (const std::exception&)
{
QVERIFY("Should get here");
}
}
void ribi::cmap::QtCommandSetConceptTest::FailsWithoutSelected() const noexcept
{
QtConceptMap q;
q.SetConceptMap(ConceptMapFactory().GetLonelyCenterNode());
SetSelectedness(true, *GetFirstQtNode(q));
q.show();
assert(CountSelectedQtNodes(q) == 1);
try
{
q.DoCommand(new CommandSetConcept(q, Concept()));
assert(!"Should not get here");
}
catch (const std::exception&)
{
QVERIFY("Should get here");
}
}
void ribi::cmap::QtCommandSetConceptTest::Parse() const noexcept
{
QtConceptMap q;
q.DoCommand(new CommandCreateNewNode(q));
assert(IsSelected(*GetFirstQtNode(q)));
const Concept concept("my name");
const std::string xml = ToXml(concept);
const std::string cmd = "set_concept(" + xml + ")";
const auto c = ParseCommandSetConcept(q, cmd);
assert(c);
QVERIFY(c != nullptr);
}
void ribi::cmap::QtCommandSetConceptTest::ParseNonsenseFails() const noexcept
{
QtConceptMap q;
QVERIFY(ParseCommandSetConcept(q, "nonsense") == nullptr);
}
void ribi::cmap::QtCommandSetConceptTest
::SetConceptWithExamplesAtQtEdge() const noexcept
{
QtConceptMap q;
q.DoCommand(new CommandCreateNewNode(q));
q.DoCommand(new CommandCreateNewNode(q));
q.DoCommand(new CommandCreateNewEdge(q));
assert(IsSelected(*GetFirstQtEdge(q)));
const Concept concept("any name", Examples( { Example("John"), Example("Jane")} ));
q.DoCommand(new CommandSetConcept(q, concept));
const Concept concept_again = GetConcept(*GetFirstQtEdge(q));
QVERIFY(concept == concept_again);
}
void ribi::cmap::QtCommandSetConceptTest
::SetConceptWithExamplesAtQtEdgeAndUndo() const noexcept
{
QtConceptMap q;
q.DoCommand(new CommandCreateNewNode(q));
q.DoCommand(new CommandCreateNewNode(q));
q.DoCommand(new CommandCreateNewEdge(q));
assert(IsSelected(*GetFirstQtEdge(q)));
const Concept concept("any name", Examples( { Example("John"), Example("Jane")} ));
q.DoCommand(new CommandSetConcept(q, concept));
assert(concept == GetConcept(*GetFirstQtEdge(q)));
q.Undo();
const Concept concept_again = GetConcept(*GetFirstQtEdge(q));
QVERIFY(concept != concept_again);
}
void ribi::cmap::QtCommandSetConceptTest
::SetConceptWithExamplesAtQtNode() const noexcept
{
QtConceptMap q;
q.DoCommand(new CommandCreateNewNode(q));
assert(IsSelected(*GetFirstQtNode(q)));
const Concept concept("any name", Examples( { Example("John"), Example("Jane")} ));
q.DoCommand(new CommandSetConcept(q, concept));
const Concept concept_again = GetConcept(*GetFirstQtNode(q));
QVERIFY(concept == concept_again);
}
void ribi::cmap::QtCommandSetConceptTest
::SetConceptWithExamplesAtQtNodeAndUndo() const noexcept
{
QtConceptMap q;
q.DoCommand(new CommandCreateNewNode(q));
assert(IsSelected(*GetFirstQtNode(q)));
const Concept concept("any name", Examples( { Example("John"), Example("Jane")} ));
q.DoCommand(new CommandSetConcept(q, concept));
q.Undo();
}
void ribi::cmap::QtCommandSetConceptTest
::SetConceptWithoutExamplesAtQtNodeWithExamples() const noexcept
{
QtConceptMap q;
q.DoCommand(new CommandCreateNewNode(q));
assert(IsSelected(*GetFirstQtNode(q)));
const Concept concept_with_examples("any name", Examples( { Example("John"), Example("Jane")} ));
q.DoCommand(new CommandSetConcept(q, concept_with_examples));
const Concept concept_without_examples("concept without examples");
q.DoCommand(new CommandSetConcept(q, concept_without_examples));
}
void ribi::cmap::QtCommandSetConceptTest
::SetConceptWithoutExamplesAtQtNodeWithExamplesAndUndo() const noexcept
{
QtConceptMap q;
q.DoCommand(new CommandCreateNewNode(q));
assert(IsSelected(*GetFirstQtNode(q)));
const Concept concept_with_examples("any name", Examples( { Example("John"), Example("Jane")} ));
q.DoCommand(new CommandSetConcept(q, concept_with_examples));
const Concept concept_without_examples("concept without examples");
q.DoCommand(new CommandSetConcept(q, concept_without_examples));
q.Undo();
}