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 package org.jaxen.function;
63
64 import java.io.IOException;
65
66 import javax.xml.parsers.DocumentBuilder;
67 import javax.xml.parsers.DocumentBuilderFactory;
68 import javax.xml.parsers.ParserConfigurationException;
69
70 import junit.framework.TestCase;
71
72 import org.jaxen.BaseXPath;
73 import org.jaxen.FunctionCallException;
74 import org.jaxen.JaxenException;
75 import org.jaxen.dom.DOMXPath;
76 import org.w3c.dom.Document;
77 import org.xml.sax.SAXException;
78
79 /***
80 * @author Elliotte Rusty Harold
81 *
82 */
83 public class CeilingTest extends TestCase {
84
85 private Document doc;
86
87 public void setUp() throws ParserConfigurationException, SAXException, IOException
88 {
89 DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
90 factory.setNamespaceAware(true);
91 DocumentBuilder builder = factory.newDocumentBuilder();
92 doc = builder.newDocument();
93 org.w3c.dom.Element a = doc.createElementNS("", "a");
94 doc.appendChild(a);
95 }
96
97
98 public CeilingTest(String name) {
99 super(name);
100 }
101
102
103
104 public void testCeiling() throws JaxenException {
105
106 BaseXPath xpath = new DOMXPath("ceiling(1.5)");
107
108 Object result = xpath.evaluate(doc);
109 assertEquals(2, ((Double) result).doubleValue(), 0.0001);
110
111 }
112
113 public void testNegativeCeiling() throws JaxenException {
114
115 BaseXPath xpath = new DOMXPath("ceiling(-1.5)");
116
117 Object result = xpath.evaluate(doc);
118 assertEquals(-1, ((Double) result).doubleValue(), 0.0001);
119
120 }
121
122 public void testNaNCeilingIsNaN() throws JaxenException {
123 BaseXPath xpath = new DOMXPath("ceiling(1.0 div 0.0 - 2.0 div 0.0)");
124 double result = ((Double) xpath.evaluate(doc)).doubleValue();
125 assertTrue(Double.isNaN(result));
126 }
127
128 public void testCeilingFunctionRequiresAtLeastArgument()
129 throws JaxenException {
130
131 BaseXPath xpath = new DOMXPath("ceiling()");
132
133 try {
134 xpath.selectNodes(doc);
135 fail("Allowed ceiling function with no arguments");
136 }
137 catch (FunctionCallException ex) {
138 assertNotNull(ex.getMessage());
139 }
140
141 }
142
143 public void testBooleanFunctionRequiresExactlyOneArgument()
144 throws JaxenException {
145
146 BaseXPath xpath = new DOMXPath("ceiling(2.2, 1.2)");
147
148 try {
149 xpath.selectNodes(doc);
150 fail("Allowed ceiling function with two arguments");
151 }
152 catch (FunctionCallException ex) {
153 assertNotNull(ex.getMessage());
154 }
155
156 }
157
158 }