|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
SuccessMessageBuilder | Line # 12 | 32 | 0% | 45 | 1 | 98.3% |
0.98333335
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||
(43) | |||
Result | |||
0.73333335
|
org.kuali.student.common.messagebuilder.impl.SuccessMessageBuilderTest.testBuildSuccessMessageForListOfNodes_Complex org.kuali.student.common.messagebuilder.impl.SuccessMessageBuilderTest.testBuildSuccessMessageForListOfNodes_Complex | 1 PASS | |
0.6666667
|
org.kuali.student.common.messagebuilder.impl.SuccessMessageBuilderTest.testBuildSuccessMessageForListOfNodes org.kuali.student.common.messagebuilder.impl.SuccessMessageBuilderTest.testBuildSuccessMessageForListOfNodes | 1 PASS | |
0.55
|
org.kuali.student.common.messagebuilder.impl.SuccessFailureMessageBuilderTest.testBuildSuccessMessageForListOfNodes_Complex org.kuali.student.common.messagebuilder.impl.SuccessFailureMessageBuilderTest.testBuildSuccessMessageForListOfNodes_Complex | 1 PASS | |
0.55
|
org.kuali.student.common.messagebuilder.impl.SuccessFailureMessageBuilderTest.testBuildFailureMessage org.kuali.student.common.messagebuilder.impl.SuccessFailureMessageBuilderTest.testBuildFailureMessage | 1 PASS | |
0.53333336
|
org.kuali.student.common.messagebuilder.impl.SuccessFailureMessageBuilderTest.testBuildFailureMessage org.kuali.student.common.messagebuilder.impl.SuccessFailureMessageBuilderTest.testBuildFailureMessage | 1 PASS | |
0.51666665
|
org.kuali.student.common.messagebuilder.impl.SuccessFailureMessageBuilderTest.testBuildFailureMessage org.kuali.student.common.messagebuilder.impl.SuccessFailureMessageBuilderTest.testBuildFailureMessage | 1 PASS | |
0.51666665
|
org.kuali.student.common.messagebuilder.impl.MessageBuilderImplTest.testBuildMessage10 org.kuali.student.common.messagebuilder.impl.MessageBuilderImplTest.testBuildMessage10 | 1 PASS | |
0.51666665
|
org.kuali.student.common.messagebuilder.impl.MessageBuilderImplTest.testBuildMessage6 org.kuali.student.common.messagebuilder.impl.MessageBuilderImplTest.testBuildMessage6 | 1 PASS | |
0.5
|
org.kuali.student.common.messagebuilder.impl.MessageBuilderImplTest.testBuildMessage9 org.kuali.student.common.messagebuilder.impl.MessageBuilderImplTest.testBuildMessage9 | 1 PASS | |
0.5
|
org.kuali.student.common.messagebuilder.impl.MessageBuilderImplTest.testBuildMessage5_True org.kuali.student.common.messagebuilder.impl.MessageBuilderImplTest.testBuildMessage5_True | 1 PASS | |
0.5
|
org.kuali.student.common.messagebuilder.impl.MessageBuilderImplTest.testBuildMessage8 org.kuali.student.common.messagebuilder.impl.MessageBuilderImplTest.testBuildMessage8 | 1 PASS | |
0.5
|
org.kuali.student.common.messagebuilder.impl.MessageBuilderImplTest.testBuildMessage11 org.kuali.student.common.messagebuilder.impl.MessageBuilderImplTest.testBuildMessage11 | 1 PASS | |
0.48333332
|
org.kuali.student.common.messagebuilder.impl.MessageBuilderImplTest.testBuildMessage12 org.kuali.student.common.messagebuilder.impl.MessageBuilderImplTest.testBuildMessage12 | 1 PASS | |
0.48333332
|
org.kuali.student.common.messagebuilder.impl.MessageBuilderImplTest.testBuildMessage7 org.kuali.student.common.messagebuilder.impl.MessageBuilderImplTest.testBuildMessage7 | 1 PASS | |
0.48333332
|
org.kuali.student.common.messagebuilder.impl.SuccessMessageBuilderTest.testBuildSuccessMessageForListOfNodes_MultipleRootNodes org.kuali.student.common.messagebuilder.impl.SuccessMessageBuilderTest.testBuildSuccessMessageForListOfNodes_MultipleRootNodes | 1 PASS | |
0.45
|
org.kuali.student.common.messagebuilder.impl.MessageBuilderImplTest.testBuildMessage2_True org.kuali.student.common.messagebuilder.impl.MessageBuilderImplTest.testBuildMessage2_True | 1 PASS | |
0.33333334
|
org.kuali.student.common.messagebuilder.impl.MessageBuilderImplTest.testBuildMessage13 org.kuali.student.common.messagebuilder.impl.MessageBuilderImplTest.testBuildMessage13 | 1 PASS | |
0.33333334
|
org.kuali.student.common.messagebuilder.impl.MessageBuilderImplTest.testBuildMessage4_False org.kuali.student.common.messagebuilder.impl.MessageBuilderImplTest.testBuildMessage4_False | 1 PASS | |
0.31666666
|
org.kuali.student.common.messagebuilder.impl.MessageBuilderImplTest.testBuildMessage4_False org.kuali.student.common.messagebuilder.impl.MessageBuilderImplTest.testBuildMessage4_False | 1 PASS | |
0.31666666
|
org.kuali.student.common.messagebuilder.impl.MessageBuilderImplTest.testBuildMessage4_False org.kuali.student.common.messagebuilder.impl.MessageBuilderImplTest.testBuildMessage4_False | 1 PASS | |
0.31666666
|
org.kuali.student.common.messagebuilder.impl.MessageBuilderImplTest.testBuildMessage4_False org.kuali.student.common.messagebuilder.impl.MessageBuilderImplTest.testBuildMessage4_False | 1 PASS | |
0.31666666
|
org.kuali.student.common.messagebuilder.impl.SuccessMessageBuilderTest.testBuildSuccessMessageForSingleOr1Node org.kuali.student.common.messagebuilder.impl.SuccessMessageBuilderTest.testBuildSuccessMessageForSingleOr1Node | 1 PASS | |
0.31666666
|
org.kuali.student.common.messagebuilder.impl.SuccessFailureMessageBuilderTest.testBuildSuccessMessageForListOfNodes_MultipleRootNodes org.kuali.student.common.messagebuilder.impl.SuccessFailureMessageBuilderTest.testBuildSuccessMessageForListOfNodes_MultipleRootNodes | 1 PASS | |
0.31666666
|
org.kuali.student.common.messagebuilder.impl.SuccessFailureMessageBuilderTest.testBuildSuccessMessageForListOfNodes_MultipleRootNodes org.kuali.student.common.messagebuilder.impl.SuccessFailureMessageBuilderTest.testBuildSuccessMessageForListOfNodes_MultipleRootNodes | 1 PASS | |
0.31666666
|
org.kuali.student.common.messagebuilder.impl.SuccessFailureMessageBuilderTest.testBuildSuccessMessageForListOfNodes_MultipleRootNodes org.kuali.student.common.messagebuilder.impl.SuccessFailureMessageBuilderTest.testBuildSuccessMessageForListOfNodes_MultipleRootNodes | 1 PASS | |
0.3
|
org.kuali.student.common.messagebuilder.impl.SuccessMessageBuilderTest.testBuildSuccessMessageForSingleOr2Node org.kuali.student.common.messagebuilder.impl.SuccessMessageBuilderTest.testBuildSuccessMessageForSingleOr2Node | 1 PASS | |
0.25
|
org.kuali.student.common.messagebuilder.impl.MessageBuilderImplTest.testBuildMessage1_True org.kuali.student.common.messagebuilder.impl.MessageBuilderImplTest.testBuildMessage1_True | 1 PASS | |
0.25
|
org.kuali.student.common.messagebuilder.impl.MessageBuilderImplTest.testBuildMessageTemplate3_True org.kuali.student.common.messagebuilder.impl.MessageBuilderImplTest.testBuildMessageTemplate3_True | 1 PASS | |
0.25
|
org.kuali.student.common.messagebuilder.impl.MessageBuilderImplTest.testBuildMessageTemplate3_True org.kuali.student.common.messagebuilder.impl.MessageBuilderImplTest.testBuildMessageTemplate3_True | 1 PASS | |
0.25
|
org.kuali.student.common.messagebuilder.impl.MessageBuilderImplTest.testBuildMessageTemplate3_True org.kuali.student.common.messagebuilder.impl.MessageBuilderImplTest.testBuildMessageTemplate3_True | 1 PASS | |
0.25
|
org.kuali.student.common.messagebuilder.impl.MessageBuilderImplTest.testBuildMessageTemplate3_True org.kuali.student.common.messagebuilder.impl.MessageBuilderImplTest.testBuildMessageTemplate3_True | 1 PASS | |
0.25
|
org.kuali.student.common.messagebuilder.impl.MessageBuilderImplTest.testBuildMessageTemplate1_NullContextMap_True org.kuali.student.common.messagebuilder.impl.MessageBuilderImplTest.testBuildMessageTemplate1_NullContextMap_True | 1 PASS | |
0.2
|
org.kuali.student.common.messagebuilder.impl.SuccessMessageBuilderTest.testBuildSuccessMessageForSingleAndNode org.kuali.student.common.messagebuilder.impl.SuccessMessageBuilderTest.testBuildSuccessMessageForSingleAndNode | 1 PASS | |
0.18333334
|
org.kuali.student.common.messagebuilder.impl.MessageBuilderImplTest.testBuildMessageTemplate4_False org.kuali.student.common.messagebuilder.impl.MessageBuilderImplTest.testBuildMessageTemplate4_False | 1 PASS | |
0.18333334
|
org.kuali.student.common.messagebuilder.impl.MessageBuilderImplTest.testBuildMessageTemplate2_NullContextMap_False org.kuali.student.common.messagebuilder.impl.MessageBuilderImplTest.testBuildMessageTemplate2_NullContextMap_False | 1 PASS | |
0.18333334
|
org.kuali.student.common.messagebuilder.impl.MessageBuilderImplTest.testBuildMessage3_False org.kuali.student.common.messagebuilder.impl.MessageBuilderImplTest.testBuildMessage3_False | 1 PASS | |
0.1
|
org.kuali.student.common.messagebuilder.impl.MessageBuilderImplTest.testBuildMessage3_False org.kuali.student.common.messagebuilder.impl.MessageBuilderImplTest.testBuildMessage3_False | 1 PASS | |
0.1
|
org.kuali.student.common.messagebuilder.impl.MessageBuilderImplTest.testBuildMessage3_False org.kuali.student.common.messagebuilder.impl.MessageBuilderImplTest.testBuildMessage3_False | 1 PASS | |
0.1
|
org.kuali.student.common.messagebuilder.impl.MessageBuilderImplTest.testBuildMessage3_False org.kuali.student.common.messagebuilder.impl.MessageBuilderImplTest.testBuildMessage3_False | 1 PASS | |
0.1
|
org.kuali.student.common.messagebuilder.impl.MessageBuilderImplTest.testBuildMessage3_False org.kuali.student.common.messagebuilder.impl.MessageBuilderImplTest.testBuildMessage3_False | 1 PASS | |
0.1
|
org.kuali.student.common.messagebuilder.impl.MessageBuilderImplTest.testBuildMessage3_False org.kuali.student.common.messagebuilder.impl.MessageBuilderImplTest.testBuildMessage3_False | 1 PASS | |
0.1
|
org.kuali.student.common.messagebuilder.impl.MessageBuilderImplTest.testBuildMessage3_False org.kuali.student.common.messagebuilder.impl.MessageBuilderImplTest.testBuildMessage3_False | 1 PASS | |
0.1
|
org.kuali.student.common.messagebuilder.impl.MessageBuilderImplTest.testBuildMessage3_False org.kuali.student.common.messagebuilder.impl.MessageBuilderImplTest.testBuildMessage3_False | 1 PASS | |
1 | package org.kuali.student.common.messagebuilder.impl; | |
2 | ||
3 | import java.util.ArrayList; | |
4 | import java.util.List; | |
5 | ||
6 | import org.kuali.student.common.messagebuilder.booleanmessage.ast.BooleanNode; | |
7 | import org.kuali.student.common.messagebuilder.impl.exceptions.MessageBuilderException; | |
8 | ||
9 | /** | |
10 | * This class creates success messages for boolean binary tree nodes. | |
11 | */ | |
12 | public class SuccessMessageBuilder { | |
13 | /** Boolean operators to use in creating the success message */ | |
14 | private BooleanOperators booleanOperators; | |
15 | ||
16 | /** | |
17 | * Creates a success message builder with boolean operators to use in | |
18 | * building the success message. | |
19 | * | |
20 | * @param bo Boolean operators to build success message | |
21 | */ | |
22 | 37 | public SuccessMessageBuilder(BooleanOperators bo) { |
23 | 37 | this.booleanOperators = bo; |
24 | } | |
25 | ||
26 | /** | |
27 | * Builds and sets the success message for each of the boolean nodes | |
28 | * (binary tree) in the <code>nodeList</code>. | |
29 | * | |
30 | * @param nodeList List of boolean nodes | |
31 | * @return Complete success message | |
32 | */ | |
33 | 3 | public String buildSuccessMessage(List<BooleanNode> nodeList) throws MessageBuilderException { |
34 | // List must only contain one root node | |
35 | 3 | List<BooleanNode> rootNodeList = new ArrayList<BooleanNode>(); |
36 | 3 | for(BooleanNode node : nodeList) { |
37 | 14 | if(node.getParent() == null) { |
38 | 4 | rootNodeList.add(node); |
39 | } | |
40 | 14 | buildSuccessMessage(node); |
41 | } | |
42 | 3 | if(rootNodeList.size() > 1) { |
43 | 1 | throw new MessageBuilderException("Node list contains more than one root node: " + rootNodeList); |
44 | } | |
45 | 2 | return rootNodeList.get(0).getNodeMessage(); |
46 | } | |
47 | ||
48 | /** | |
49 | * Builds and sets the success message for a single | |
50 | * boolean <code>node</code> (b-tree node). | |
51 | * | |
52 | * @param node Boolean node | |
53 | */ | |
54 | 209 | public String buildSuccessMessage(final BooleanNode node) { |
55 | // AND node | |
56 | 209 | if(node.getLabel().equals("*")) { |
57 | 44 | buildAndNodeSuccessMessage(node); |
58 | } | |
59 | // OR node | |
60 | 165 | else if(node.getLabel().equals("+")) { |
61 | 42 | buildOr1NodeSuccessMessage(node); |
62 | 42 | buildOr2NodeSuccessMessage(node); |
63 | } | |
64 | 209 | return node.getNodeMessage(); |
65 | } | |
66 | ||
67 | /** | |
68 | * Builds a success message for an AND node (b-tree node) where | |
69 | * left node and right node are true. | |
70 | * | |
71 | * @param node Boolean node | |
72 | */ | |
73 | 44 | private void buildAndNodeSuccessMessage(BooleanNode node) { |
74 | 44 | if(node.getLabel().equals("*") && |
75 | node.getLeftNode() != null && | |
76 | node.getRightNode() != null && | |
77 | node.getLeftNode().getValue() == true && | |
78 | node.getRightNode().getValue() == true && | |
79 | node.getLeftNode().getNodeMessage() != null && | |
80 | node.getRightNode().getNodeMessage() != null) { | |
81 | 32 | String logMessage = node.getLeftNode().getNodeMessage() + " " + |
82 | this.booleanOperators.getAndOperator() + " " + | |
83 | node.getRightNode().getNodeMessage(); | |
84 | ||
85 | 32 | if(node.getParent() != null && |
86 | ( (node.getLabel().equals("+") && | |
87 | node.getParent().getLabel().equals("*")) || | |
88 | (node.getLabel().equals("*") && | |
89 | node.getParent().getLabel().equals("+")))) { | |
90 | 12 | logMessage = "(" + logMessage + ")"; |
91 | } | |
92 | 32 | node.setNodeMessage(logMessage); |
93 | } | |
94 | } | |
95 | ||
96 | /** | |
97 | * Builds a success message for an OR node (b-tree node) where | |
98 | * left node is true and right node is false or | |
99 | * left node is false and right node is true. | |
100 | * | |
101 | * @param node Boolean node | |
102 | */ | |
103 | 42 | private void buildOr1NodeSuccessMessage(BooleanNode node) { |
104 | // OR1 | |
105 | 42 | if(node.getLabel().equals("+") && |
106 | node.getLeftNode() != null && | |
107 | node.getRightNode() != null && | |
108 | ((node.getLeftNode().getValue() == false && | |
109 | node.getRightNode().getValue() == true && | |
110 | node.getRightNode().getNodeMessage() != null ) || | |
111 | (node.getLeftNode().getValue() == true && | |
112 | node.getRightNode().getValue() == false && | |
113 | node.getLeftNode().getNodeMessage() != null))) { | |
114 | 14 | String logMessage = "test"; |
115 | ||
116 | 14 | if (node.getLeftNode().getValue() == true) |
117 | 10 | logMessage = node.getLeftNode().getNodeMessage(); |
118 | 4 | else if (node.getRightNode().getValue() == true) |
119 | 4 | logMessage = node.getRightNode().getNodeMessage(); |
120 | ||
121 | 14 | node.setNodeMessage(logMessage); |
122 | } | |
123 | } | |
124 | ||
125 | /** | |
126 | * Builds a success message for an OR node (b-tree node) where | |
127 | * left node and right node are true. | |
128 | * | |
129 | * @param node | |
130 | */ | |
131 | 42 | private void buildOr2NodeSuccessMessage(BooleanNode node) { |
132 | // OR2 | |
133 | 42 | if(node.getLabel().equals("+") && |
134 | node.getLeftNode() != null && | |
135 | node.getRightNode() != null && | |
136 | node.getLeftNode().getValue() == true && | |
137 | node.getRightNode().getValue() == true && | |
138 | node.getLeftNode().getNodeMessage() != null && | |
139 | node.getRightNode().getNodeMessage() != null) { | |
140 | 23 | String logMessage = node.getLeftNode().getNodeMessage() + " " + |
141 | this.booleanOperators.getOrOperator() + " " + | |
142 | node.getRightNode().getNodeMessage(); | |
143 | ||
144 | 23 | if(node.getParent() != null && |
145 | ( (node.getLabel().equals("+") && | |
146 | node.getParent().getLabel().equals("*")) || | |
147 | (node.getLabel().equals("*") && | |
148 | node.getParent().getLabel().equals("+")))) { | |
149 | 7 | logMessage = "(" + logMessage + ")"; |
150 | } | |
151 | 23 | node.setNodeMessage(logMessage); |
152 | } | |
153 | } | |
154 | } |
|