1
+ require 'abstract_unit'
2
+ require 'active_support/testing/performance'
3
+
4
+
5
+ module ActiveSupport
6
+ module Testing
7
+ class PerformanceTest < ActiveSupport ::TestCase
8
+ def test_amount_format
9
+ amount_metric = ActiveSupport ::Testing ::Performance ::Metrics [ :amount ] . new
10
+ assert_equal "0" , amount_metric . format ( 0 )
11
+ assert_equal "1" , amount_metric . format ( 1.23 )
12
+ assert_equal "40,000,000" , amount_metric . format ( 40000000 )
13
+ end
14
+
15
+ def test_time_format
16
+ time_metric = ActiveSupport ::Testing ::Performance ::Metrics [ :time ] . new
17
+ assert_equal "0 ms" , time_metric . format ( 0 )
18
+ assert_equal "40 ms" , time_metric . format ( 0.04 )
19
+ assert_equal "41 ms" , time_metric . format ( 0.0415 )
20
+ assert_equal "1.23 sec" , time_metric . format ( 1.23 )
21
+ assert_equal "40000.00 sec" , time_metric . format ( 40000 )
22
+ assert_equal "-5000 ms" , time_metric . format ( -5 )
23
+ end
24
+
25
+ def test_space_format
26
+ space_metric = ActiveSupport ::Testing ::Performance ::Metrics [ :digital_information_unit ] . new
27
+ assert_equal "0 Bytes" , space_metric . format ( 0 )
28
+ assert_equal "0 Bytes" , space_metric . format ( 0.4 )
29
+ assert_equal "1 Byte" , space_metric . format ( 1.23 )
30
+ assert_equal "123 Bytes" , space_metric . format ( 123 )
31
+ assert_equal "123 Bytes" , space_metric . format ( 123.45 )
32
+ assert_equal "12 KB" , space_metric . format ( 12345 )
33
+ assert_equal "1.2 MB" , space_metric . format ( 1234567 )
34
+ assert_equal "9.3 GB" , space_metric . format ( 10 **10 )
35
+ assert_equal "91 TB" , space_metric . format ( 10 **14 )
36
+ assert_equal "910000 TB" , space_metric . format ( 10 **18 )
37
+ end
38
+ end
39
+ end
40
+ end
0 commit comments