|
| 1 | +/* |
| 2 | + This file is licensed to You under the Apache License, Version 2.0 |
| 3 | + (the "License"); you may not use this file except in compliance with |
| 4 | + the License. You may obtain a copy of the License at |
| 5 | +
|
| 6 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 7 | +
|
| 8 | + Unless required by applicable law or agreed to in writing, software |
| 9 | + distributed under the License is distributed on an "AS IS" BASIS, |
| 10 | + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 11 | + See the License for the specific language governing permissions and |
| 12 | + limitations under the License. |
| 13 | +*/ |
| 14 | + |
| 15 | +using NUnit.Framework; |
| 16 | +using Org.XmlUnit; |
| 17 | +using Org.XmlUnit.Diff; |
| 18 | + |
| 19 | +namespace Org.XmlUnit.Placeholder { |
| 20 | + |
| 21 | + [TestFixture] |
| 22 | + public class IsNumberPlaceholderHandlerTest { |
| 23 | + private IPlaceholderHandler placeholderHandler = new IsNumberPlaceholderHandler(); |
| 24 | + |
| 25 | + [Test] |
| 26 | + public void ShouldGetKeyword() { |
| 27 | + string expected = "isNumber"; |
| 28 | + string keyword = placeholderHandler.Keyword; |
| 29 | + |
| 30 | + Assert.AreEqual(expected, keyword); |
| 31 | + } |
| 32 | + |
| 33 | + [Test] |
| 34 | + public void ShouldEvaluateGivenSimpleNumber() { |
| 35 | + string testTest = "1234"; |
| 36 | + ComparisonResult comparisonResult = placeholderHandler.Evaluate(testTest); |
| 37 | + |
| 38 | + Assert.AreEqual(ComparisonResult.EQUAL, comparisonResult); |
| 39 | + } |
| 40 | + |
| 41 | + [Test] |
| 42 | + public void ShouldEvaluateGivenFloatingPointNumber() { |
| 43 | + string testTest = "12.34"; |
| 44 | + ComparisonResult comparisonResult = placeholderHandler.Evaluate(testTest); |
| 45 | + |
| 46 | + Assert.AreEqual(ComparisonResult.EQUAL, comparisonResult); |
| 47 | + } |
| 48 | + |
| 49 | + [Test] |
| 50 | + public void ShouldEvaluateGivenNegativeNumber() { |
| 51 | + string testTest = "-1234"; |
| 52 | + ComparisonResult comparisonResult = placeholderHandler.Evaluate(testTest); |
| 53 | + |
| 54 | + Assert.AreEqual(ComparisonResult.EQUAL, comparisonResult); |
| 55 | + } |
| 56 | + |
| 57 | + [Test] |
| 58 | + public void ShouldEvaluateGivenNegativeFloatingPointNumber() { |
| 59 | + string testTest = "-12.34"; |
| 60 | + ComparisonResult comparisonResult = placeholderHandler.Evaluate(testTest); |
| 61 | + |
| 62 | + Assert.AreEqual(ComparisonResult.EQUAL, comparisonResult); |
| 63 | + } |
| 64 | + |
| 65 | + [Test] |
| 66 | + public void ShouldEvaluateGivenEngineeringNotationFloatingPointNumber() { |
| 67 | + string testTest = "1.7E+3"; |
| 68 | + ComparisonResult comparisonResult = placeholderHandler.Evaluate(testTest); |
| 69 | + |
| 70 | + Assert.AreEqual(ComparisonResult.EQUAL, comparisonResult); |
| 71 | + } |
| 72 | + |
| 73 | + [Test] |
| 74 | + public void ShouldEvaluateGivenNegativeEngineeringNotationFloatingPointNumber() { |
| 75 | + string testTest = "-1.7E+3"; |
| 76 | + ComparisonResult comparisonResult = placeholderHandler.Evaluate(testTest); |
| 77 | + |
| 78 | + Assert.AreEqual(ComparisonResult.EQUAL, comparisonResult); |
| 79 | + } |
| 80 | + |
| 81 | + [Test] |
| 82 | + public void ShouldNotEvaluateGivenNull() { |
| 83 | + string testTest = null; |
| 84 | + ComparisonResult comparisonResult = placeholderHandler.Evaluate(testTest); |
| 85 | + |
| 86 | + Assert.AreEqual(ComparisonResult.DIFFERENT, comparisonResult); |
| 87 | + } |
| 88 | + |
| 89 | + [Test] |
| 90 | + public void ShouldNotEvaluateGivenEmptystring() { |
| 91 | + string testTest = ""; |
| 92 | + ComparisonResult comparisonResult = placeholderHandler.Evaluate(testTest); |
| 93 | + |
| 94 | + Assert.AreEqual(ComparisonResult.DIFFERENT, comparisonResult); |
| 95 | + } |
| 96 | + |
| 97 | + [Test] |
| 98 | + public void ShouldNotEvaluateGivenNonNumberstring() { |
| 99 | + string testTest = "not parsable as a number even though it contains 123 numbers"; |
| 100 | + ComparisonResult comparisonResult = placeholderHandler.Evaluate(testTest); |
| 101 | + |
| 102 | + Assert.AreEqual(ComparisonResult.DIFFERENT, comparisonResult); |
| 103 | + } |
| 104 | + |
| 105 | + } |
| 106 | +} |
0 commit comments