Debian Codegraph @

closure-library/closure/goog/labs/testing/numbermatcher_test.js

raw
1 // Copyright 2012 The Closure Library Authors. All Rights Reserved.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS-IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 goog.provide('goog.labs.testing.numberMatcherTest');
16 goog.setTestOnly('goog.labs.testing.numberMatcherTest');
17
18 /** @suppress {extraRequire} */
19 goog.require('goog.labs.testing.LessThanMatcher');
20 goog.require('goog.labs.testing.MatcherError');
21 goog.require('goog.labs.testing.assertThat');
22 goog.require('goog.testing.jsunit');
23
24 function testAnyNumber() {
25 goog.labs.testing.assertThat(0, anyNumber(3), 'typeof 0 == "number"');
26 assertMatcherError(function() {
27 goog.labs.testing.assertThat('chicken', anyNumber());
28 }, 'typeof "chicken" == "number"');
29 }
30
31 function testGreaterThan() {
32 goog.labs.testing.assertThat(4, greaterThan(3), '4 > 3');
33 assertMatcherError(function() {
34 goog.labs.testing.assertThat(2, greaterThan(3));
35 }, '2 > 3');
36 }
37
38 function testGreaterThanEqualTo() {
39 goog.labs.testing.assertThat(5, greaterThanEqualTo(4), '5 >= 4');
40 goog.labs.testing.assertThat(5, greaterThanEqualTo(5), '5 >= 5');
41 assertMatcherError(function() {
42 goog.labs.testing.assertThat(3, greaterThanEqualTo(5));
43 }, '3 >= 5');
44 }
45
46 function testLessThan() {
47 goog.labs.testing.assertThat(6, lessThan(7), '6 < 7');
48 assertMatcherError(function() {
49 goog.labs.testing.assertThat(7, lessThan(5));
50 }, '7 < 5');
51 }
52
53 function testLessThanEqualTo() {
54 goog.labs.testing.assertThat(8, lessThanEqualTo(8), '8 <= 8');
55 goog.labs.testing.assertThat(8, lessThanEqualTo(9), '8 <= 9');
56 assertMatcherError(function() {
57 goog.labs.testing.assertThat(7, lessThanEqualTo(5));
58 }, '7 <= 5');
59 }
60
61 function testEqualTo() {
62 goog.labs.testing.assertThat(7, equalTo(7), '7 equals 7');
63 assertMatcherError(function() {
64 goog.labs.testing.assertThat(7, equalTo(5));
65 }, '7 == 5');
66 }
67
68 function testCloseTo() {
69 goog.labs.testing.assertThat(7, closeTo(10, 4), '7 within range(4) of 10');
70 assertMatcherError(function() {
71 goog.labs.testing.assertThat(5, closeTo(10, 3));
72 }, '5 within range(3) of 10');
73 }
74
75 function assertMatcherError(callable, errorString) {
76 var e = assertThrows(errorString || 'callable throws exception', callable);
77 assertTrue(e instanceof goog.labs.testing.MatcherError);
78 }