1
+ /*
2
+ * Copyright 2019 Philipp Salvisberg <philipp.salvisberg@trivadis.com>
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ package org.utplsql.sqldev.test.runner
17
+
18
+ import org.junit.Assert
19
+ import org.junit.Test
20
+ import org.utplsql.sqldev.ui.runner.SmartTime
21
+
22
+ class SmartTimeTest {
23
+
24
+ @Test
25
+ def null_default () {
26
+ val effective = (new SmartTime (null , false )). toString
27
+ Assert . assertEquals(null , effective);
28
+ }
29
+
30
+ @Test
31
+ def null_smart () {
32
+ val effective = (new SmartTime (null , true )). toString
33
+ Assert . assertEquals(null , effective);
34
+ }
35
+
36
+ @Test
37
+ def ms_0_default () {
38
+ val effective = (new SmartTime (0.0 , false )). toString
39
+ Assert . assertEquals(" 0.000" , effective);
40
+ }
41
+
42
+ @Test
43
+ def ms_0_smart () {
44
+ val effective = (new SmartTime (0.0 , true )). toString
45
+ Assert . assertEquals(" 0 ms" , effective);
46
+ }
47
+
48
+ @Test
49
+ def ms_999_default () {
50
+ val effective = (new SmartTime (0.999 , false )). toString
51
+ Assert . assertEquals(" 0.999" , effective);
52
+ }
53
+
54
+ @Test
55
+ def ms_999_smart () {
56
+ val effective = (new SmartTime (0.999 , true )). toString
57
+ Assert . assertEquals(" 999 ms" , effective);
58
+ }
59
+
60
+ @Test
61
+ def s_1_default () {
62
+ val effective = (new SmartTime (1.0 , false )). toString
63
+ Assert . assertEquals(" 1.000" , effective);
64
+ }
65
+
66
+ @Test
67
+ def s_1_smart () {
68
+ val effective = (new SmartTime (1.0 , true )). toString
69
+ Assert . assertEquals(" 1.000 s" , effective);
70
+ }
71
+
72
+ @Test
73
+ def s_59_default () {
74
+ val effective = (new SmartTime (59.999 , false )). toString
75
+ Assert . assertEquals(" 59.999" , effective);
76
+ }
77
+
78
+ @Test
79
+ def s_59_smart () {
80
+ val effective = (new SmartTime (59.999 , true )). toString
81
+ Assert . assertEquals(" 59.999 s" , effective);
82
+ }
83
+
84
+ @Test
85
+ def min_1_default () {
86
+ val effective = (new SmartTime (60.0 , false )). toString
87
+ Assert . assertEquals(" 60.000" , effective);
88
+ }
89
+
90
+ @Test
91
+ def min_1_smart () {
92
+ val effective = (new SmartTime (60.0 , true )). toString
93
+ Assert . assertEquals(" 1.00 min" , effective);
94
+ }
95
+
96
+ @Test
97
+ def min_59_default () {
98
+ val effective = (new SmartTime (3599.999 , false )). toString
99
+ Assert . assertEquals(" 3,599.999" , effective);
100
+ }
101
+
102
+ @Test
103
+ def min_59_smart_and_rounded () {
104
+ val effective = (new SmartTime (3599.999 , true )). toString
105
+ Assert . assertEquals(" 60.00 min" , effective);
106
+ }
107
+
108
+ @Test
109
+ def h_1_default () {
110
+ val effective = (new SmartTime (3600.0 , false )). toString
111
+ Assert . assertEquals(" 3,600.000" , effective);
112
+ }
113
+
114
+ @Test
115
+ def h_1_smart () {
116
+ val effective = (new SmartTime (3600.0 , true )). toString
117
+ Assert . assertEquals(" 1.00 h" , effective);
118
+ }
119
+
120
+ @Test
121
+ def h_max_default () {
122
+ val effective = (new SmartTime (99999.999 , false )). toString
123
+ Assert . assertEquals(" 99,999.999" , effective);
124
+ }
125
+
126
+ @Test
127
+ def h_max_smart () {
128
+ val effective = (new SmartTime (99999.999 , true )). toString
129
+ Assert . assertEquals(" 27.78 h" , effective);
130
+ }
131
+
132
+ @Test
133
+ def h_higher_than_max_default () {
134
+ // larger than format mask
135
+ // grouping separator applied, even if not specified in format mask
136
+ val effective = (new SmartTime (100000000.0 , false )). toString
137
+ Assert . assertEquals(" 100,000,000.000" , effective);
138
+ }
139
+
140
+ @Test
141
+ def h_higher_than_max_smart () {
142
+ // larger than format mask
143
+ // no grouping separator applied (that's ok)
144
+ val effective = (new SmartTime (100000000.0 , true )). toString
145
+ Assert . assertEquals(" 27777.78 h" , effective);
146
+ }
147
+ }
0 commit comments