fiscalizer 0.0.12 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +2 -1
- data/.rspec +2 -0
- data/Gemfile +0 -4
- data/LICENSE.txt +1 -1
- data/README.md +187 -171
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/doc/Tehnicka specifikacija za korisnike 1.4.pdf +0 -0
- data/fiscalizer.gemspec +14 -13
- data/lib/fiscalizer.rb +33 -4
- data/lib/fiscalizer/constants.rb +11 -0
- data/lib/fiscalizer/data_objects/echo.rb +10 -0
- data/lib/fiscalizer/data_objects/fee.rb +18 -0
- data/lib/fiscalizer/data_objects/invoice.rb +79 -0
- data/lib/fiscalizer/data_objects/office.rb +41 -0
- data/lib/fiscalizer/{tax.rb → data_objects/tax.rb} +3 -5
- data/lib/fiscalizer/deserializers/base.rb +58 -0
- data/lib/fiscalizer/deserializers/echo.rb +13 -0
- data/lib/fiscalizer/deserializers/invoice.rb +9 -0
- data/lib/fiscalizer/deserializers/office.rb +6 -0
- data/lib/fiscalizer/fiscalizer.rb +36 -152
- data/lib/fiscalizer/fiscalizers/base.rb +54 -0
- data/lib/fiscalizer/fiscalizers/echo.rb +13 -0
- data/lib/fiscalizer/fiscalizers/invoice.rb +24 -0
- data/lib/fiscalizer/fiscalizers/office.rb +15 -0
- data/lib/fiscalizer/serializers/base.rb +58 -0
- data/lib/fiscalizer/serializers/echo.rb +21 -0
- data/lib/fiscalizer/serializers/invoice.rb +92 -0
- data/lib/fiscalizer/serializers/office.rb +85 -0
- data/lib/fiscalizer/serializers/signature.rb +62 -0
- data/lib/fiscalizer/serializers/tax.rb +81 -0
- data/lib/fiscalizer/services/request_sender.rb +68 -0
- data/lib/fiscalizer/services/security_code_generator.rb +29 -0
- data/lib/fiscalizer/version.rb +1 -1
- data/spec/fiscalizer_spec.rb +119 -0
- data/spec/spec_helper.rb +9 -0
- metadata +67 -39
- data/doc/README.md +0 -3
- data/doc/Tehnicka_specifikacija_za_korisnike_1.2.pdf +0 -0
- data/example/README.md +0 -25
- data/example/echo_P12.rb +0 -13
- data/example/echo_public_and_private_keys.rb +0 -16
- data/example/invoice_fiscalization_passing_arguments.rb +0 -44
- data/example/invoice_fiscalization_passing_object.rb +0 -48
- data/example/office_fiscalization_passing_arguments.rb +0 -22
- data/example/office_fiscalization_passing_object.rb +0 -26
- data/lib/README.md +0 -0
- data/lib/fiscalizer/README.md +0 -9
- data/lib/fiscalizer/communication.rb +0 -305
- data/lib/fiscalizer/echo.rb +0 -11
- data/lib/fiscalizer/fee.rb +0 -20
- data/lib/fiscalizer/invoice.rb +0 -190
- data/lib/fiscalizer/office.rb +0 -66
- data/lib/fiscalizer/response.rb +0 -124
- data/test/README.md +0 -13
- data/test/test_echo.rb +0 -20
- data/test/test_fee +0 -64
- data/test/test_fiscalizer.rb +0 -222
- data/test/test_fiscalizer_communication.rb +0 -28
- data/test/test_invoice.rb +0 -11
- data/test/test_office.rb +0 -11
- data/test/test_tax.rb +0 -89
data/test/test_fee
DELETED
@@ -1,64 +0,0 @@
|
|
1
|
-
require "test/unit"
|
2
|
-
require "fiscalizer"
|
3
|
-
|
4
|
-
class FeeTest < Test::Unit::TestCase
|
5
|
-
|
6
|
-
def test_initialization
|
7
|
-
# Manual build
|
8
|
-
fee = Fiscalizer::Fee.new
|
9
|
-
fee.name = "My cool new fee"
|
10
|
-
fee.value = 234.16
|
11
|
-
assert_equal "My cool new fee", fee.name, "Fee's name not set"
|
12
|
-
assert_equal 234.16, fee.value, "Fee's value not set"
|
13
|
-
|
14
|
-
# Automatic build
|
15
|
-
fee = Fiscalizer::Fee.new name: "My cool new fee", value: 234.16
|
16
|
-
assert_equal "My cool new fee", fee.name, "Fee's name not set"
|
17
|
-
assert_equal 234.16, fee.value, "Fee's value not set"
|
18
|
-
end # test_initialization
|
19
|
-
|
20
|
-
def test_math
|
21
|
-
# Whole number
|
22
|
-
fee = Fiscalizer::Fee.new name: "Test", value: 100
|
23
|
-
assert_equal 100, fee.value, "Whole number is wrong"
|
24
|
-
|
25
|
-
# Decimal number
|
26
|
-
fee = Fiscalizer::Fee.new name: "Test", value: 13.67
|
27
|
-
assert_equal 13.67, fee.value, "Decimal number is wrong"
|
28
|
-
|
29
|
-
# Decimal whole number
|
30
|
-
fee = Fiscalizer::Fee.new name: "Test", value: 13.00
|
31
|
-
assert_equal 13.00, fee.value, "Decimal whole number is wrong"
|
32
|
-
|
33
|
-
# Rounding down
|
34
|
-
fee = Fiscalizer::Fee.new name: "Test", value: 13.674961205
|
35
|
-
assert_equal 13.67, fee.value, "Rounding down is wrong"
|
36
|
-
|
37
|
-
# Rounding up
|
38
|
-
fee = Fiscalizer::Fee.new name: "Test", value: 13.675961205
|
39
|
-
assert_equal 13.68, fee.value, "Rounding down is wrong"
|
40
|
-
end # test_math
|
41
|
-
|
42
|
-
def test_string
|
43
|
-
# Whole number
|
44
|
-
fee = Fiscalizer::Fee.new name: "Test", value: 100
|
45
|
-
assert_equal "100.00", fee.value_str, "Whole number string is wrong"
|
46
|
-
|
47
|
-
# Decimal number
|
48
|
-
fee = Fiscalizer::Fee.new name: "Test", value: 13.67
|
49
|
-
assert_equal "13.67", fee.value_str, "Decimal number string is wrong"
|
50
|
-
|
51
|
-
# Decimal whole number
|
52
|
-
fee = Fiscalizer::Fee.new name: "Test", value: 13.00
|
53
|
-
assert_equal "13.00", fee.value_str, "Decimal whole number string is wrong"
|
54
|
-
|
55
|
-
# Rounding down
|
56
|
-
fee = Fiscalizer::Fee.new name: "Test", value: 13.674961205
|
57
|
-
assert_equal "13.67", fee.value_str, "Rounding down string is wrong"
|
58
|
-
|
59
|
-
# Rounding up
|
60
|
-
fee = Fiscalizer::Fee.new name: "Test", value: 13.675961205
|
61
|
-
assert_equal "13.68", fee.value_str, "Rounding down string is wrong"
|
62
|
-
end # test_string
|
63
|
-
|
64
|
-
end
|
data/test/test_fiscalizer.rb
DELETED
@@ -1,222 +0,0 @@
|
|
1
|
-
require "test/unit"
|
2
|
-
require "fiscalizer"
|
3
|
-
require 'nokogiri'
|
4
|
-
require 'openssl'
|
5
|
-
|
6
|
-
class FiscalizerTest < Test::Unit::TestCase
|
7
|
-
# Configure
|
8
|
-
KEY_PUBLIC_PATH = "/test/assets/fiskal1.cert"
|
9
|
-
KEY_PRIVATE_PATH = "/test/assets/privateKey.key"
|
10
|
-
CERTIFICATE_PATH = "/test/assets/democacert.pem"
|
11
|
-
CERTIFICATE_P12_PATH = "/test/assets/fiskal1.pfx"
|
12
|
-
URL_FISKAL = "https://cistest.apis-it.hr:8449/FiskalizacijaServiceTest"
|
13
|
-
CER_ISSUED = "OU=DEMO,O=FINA,C=HR"
|
14
|
-
PASSWORD = "12345678"
|
15
|
-
# Use P12
|
16
|
-
EXPORTED_KEYS = false
|
17
|
-
# Test specific info
|
18
|
-
UUID = "ca996cc7-fcc3-4c50-961b-40c8b875a5e8"
|
19
|
-
ECHO = "This is a simple test..."
|
20
|
-
# Personal information
|
21
|
-
PIN = "00123456789"
|
22
|
-
PIN_OPERATOR = "00000000000"
|
23
|
-
|
24
|
-
def test_initialization
|
25
|
-
# Manual build
|
26
|
-
fiscal = Fiscalizer.new
|
27
|
-
|
28
|
-
# Populate
|
29
|
-
fiscal.url = "www.somewhere.com"
|
30
|
-
fiscal.key_public_path = "path/to/my/cert.pem"
|
31
|
-
fiscal.key_private_path = "path/to/my/cert.cer"
|
32
|
-
|
33
|
-
# Test
|
34
|
-
assert_equal "www.somewhere.com", fiscal.url, "Manual URL assignment"
|
35
|
-
assert_equal "path/to/my/cert.pem", fiscal.key_public_path, "Manual public certificate location assignment"
|
36
|
-
assert_equal "path/to/my/cert.cer", fiscal.key_private_path, "Manual private certificate location assignment"
|
37
|
-
|
38
|
-
# Automatic Build
|
39
|
-
fiscal = nil
|
40
|
-
fiscal = Fiscalizer.new url: "www.somewhere.com",
|
41
|
-
key_public_path: "path/to/my/cert.pem",
|
42
|
-
key_private_path: "path/to/my/cert.cer"
|
43
|
-
|
44
|
-
# Test
|
45
|
-
assert_equal "www.somewhere.com", fiscal.url, "Automatic URL assignment"
|
46
|
-
assert_equal "path/to/my/cert.pem", fiscal.key_public_path, "Automatic public certificate location assignment"
|
47
|
-
assert_equal "path/to/my/cert.cer", fiscal.key_private_path, "Automatic private certificate location assignment"
|
48
|
-
end # fiscal_ruby_test
|
49
|
-
|
50
|
-
def test_echo
|
51
|
-
fiscal = nil
|
52
|
-
if EXPORTED_KEYS
|
53
|
-
fiscal = Fiscalizer.new url: URL_FISKAL,
|
54
|
-
key_public_path: KEY_PUBLIC_PATH,
|
55
|
-
key_private_path: KEY_PRIVATE_PATH,
|
56
|
-
certificate_path: CERTIFICATE_PATH,
|
57
|
-
certificate_issued_by: CER_ISSUED
|
58
|
-
else
|
59
|
-
fiscal = Fiscalizer.new url: URL_FISKAL,
|
60
|
-
certificate_path: CERTIFICATE_PATH,
|
61
|
-
certificate_p12_path: CERTIFICATE_P12_PATH,
|
62
|
-
certificate_issued_by: CER_ISSUED,
|
63
|
-
password: PASSWORD
|
64
|
-
end
|
65
|
-
echo = fiscal.echo text: ECHO
|
66
|
-
assert_equal ECHO, echo.response, "Echo response message does not match sent message"
|
67
|
-
assert echo.echo?, "Automatic echo check failed"
|
68
|
-
end # test_echo
|
69
|
-
|
70
|
-
def test_office
|
71
|
-
# -- Here Be Dragons --
|
72
|
-
fiscal = nil
|
73
|
-
if EXPORTED_KEYS
|
74
|
-
fiscal = Fiscalizer.new url: URL_FISKAL,
|
75
|
-
key_public_path: KEY_PUBLIC_PATH,
|
76
|
-
key_private_path: KEY_PRIVATE_PATH,
|
77
|
-
certificate_path: CERTIFICATE_PATH,
|
78
|
-
certificate_issued_by: CER_ISSUED
|
79
|
-
else
|
80
|
-
fiscal = Fiscalizer.new url: URL_FISKAL,
|
81
|
-
certificate_path: CERTIFICATE_PATH,
|
82
|
-
certificate_p12_path: CERTIFICATE_P12_PATH,
|
83
|
-
certificate_issued_by: CER_ISSUED,
|
84
|
-
password: PASSWORD
|
85
|
-
end
|
86
|
-
|
87
|
-
assert fiscal!=nil, "Failed to initialize"
|
88
|
-
# Generate invoice
|
89
|
-
office = fiscal.office uuid: UUID,
|
90
|
-
time_sent: Time.now,
|
91
|
-
pin: PIN,
|
92
|
-
office_label: "Poslovnica1",
|
93
|
-
adress_street_name: "Somewhere",
|
94
|
-
adress_house_num: "42",
|
95
|
-
adress_house_num_addendum: "AD",
|
96
|
-
adress_post_num: "10000",
|
97
|
-
adress_settlement: "Block 25-C",
|
98
|
-
adress_township: "Vogsphere",
|
99
|
-
adress_other: nil,
|
100
|
-
office_time: "Pon-Pet: 8:00-16:00",
|
101
|
-
take_effect_date: Time.now + 3600 * 24 * 7,
|
102
|
-
closure_mark: nil,
|
103
|
-
specific_purpose: nil
|
104
|
-
assert !office.errors?, "Returned an error"
|
105
|
-
assert office.uuid != nil, "'UUID' was not returned"
|
106
|
-
assert office.processed_at != nil, "'Processed at' was not returned"
|
107
|
-
end # test_office
|
108
|
-
|
109
|
-
def test_office_object
|
110
|
-
# -- Here Be Dragons --
|
111
|
-
fiscal = nil
|
112
|
-
if EXPORTED_KEYS
|
113
|
-
fiscal = Fiscalizer.new url: URL_FISKAL,
|
114
|
-
key_public_path: KEY_PUBLIC_PATH,
|
115
|
-
key_private_path: KEY_PRIVATE_PATH,
|
116
|
-
certificate_path: CERTIFICATE_PATH,
|
117
|
-
certificate_issued_by: CER_ISSUED
|
118
|
-
else
|
119
|
-
fiscal = Fiscalizer.new url: URL_FISKAL,
|
120
|
-
certificate_path: CERTIFICATE_PATH,
|
121
|
-
certificate_p12_path: CERTIFICATE_P12_PATH,
|
122
|
-
certificate_issued_by: CER_ISSUED,
|
123
|
-
password: PASSWORD
|
124
|
-
end
|
125
|
-
|
126
|
-
# Generate office
|
127
|
-
office = Fiscalizer::Office.new
|
128
|
-
office.uuid = UUID
|
129
|
-
office.time_sent = Time.now
|
130
|
-
office.pin = PIN
|
131
|
-
office.office_label = "Poslovnica1"
|
132
|
-
office.adress_street_name = "Somewhere"
|
133
|
-
office.adress_house_num = "42"
|
134
|
-
office.adress_house_num_addendum = "AD"
|
135
|
-
office.adress_post_num = "10000"
|
136
|
-
office.adress_settlement = "Block 25-C"
|
137
|
-
office.adress_township = "Vogsphere"
|
138
|
-
office.adress_other = nil
|
139
|
-
office.office_time = "Pon-Pet: 8:00-16:00"
|
140
|
-
office.take_effect_date = Time.now + 3600 * 24 * 7
|
141
|
-
office.closure_mark = nil
|
142
|
-
office.specific_purpose = nil
|
143
|
-
|
144
|
-
# Generate office
|
145
|
-
office_response = fiscal.fiscalize_office office
|
146
|
-
|
147
|
-
if office_response.errors?
|
148
|
-
puts "There were some nasty errors!"
|
149
|
-
office_response.errors.each do |error_code, error_message|
|
150
|
-
puts " " + error_code + " : " + error_message
|
151
|
-
end
|
152
|
-
end
|
153
|
-
|
154
|
-
assert !office_response.errors?, "Returned an error"
|
155
|
-
assert office_response.uuid != nil, "'UUID' was not returned"
|
156
|
-
assert office_response.processed_at != nil, "'Processed at' was not returned"
|
157
|
-
end # test_office_object
|
158
|
-
|
159
|
-
def test_invoice
|
160
|
-
# -- Here Be Dragons --
|
161
|
-
fiscal = nil
|
162
|
-
if EXPORTED_KEYS
|
163
|
-
fiscal = Fiscalizer.new url: URL_FISKAL,
|
164
|
-
key_public_path: KEY_PUBLIC_PATH,
|
165
|
-
key_private_path: KEY_PRIVATE_PATH,
|
166
|
-
certificate_path: CERTIFICATE_PATH,
|
167
|
-
certificate_issued_by: CER_ISSUED
|
168
|
-
else
|
169
|
-
fiscal = Fiscalizer.new url: URL_FISKAL,
|
170
|
-
certificate_path: CERTIFICATE_PATH,
|
171
|
-
certificate_p12_path: CERTIFICATE_P12_PATH,
|
172
|
-
certificate_issued_by: CER_ISSUED,
|
173
|
-
password: PASSWORD
|
174
|
-
end
|
175
|
-
# Generate taxes
|
176
|
-
taxes_vat = []
|
177
|
-
taxes_spending = []
|
178
|
-
taxes_other = []
|
179
|
-
(0..5).each do |i|
|
180
|
-
tax = Fiscalizer::Tax.new
|
181
|
-
tax.base = rand(10000 * 100).to_f / 100.0
|
182
|
-
tax.rate = rand(100 * 100).to_f / 100.0
|
183
|
-
taxes_vat << tax
|
184
|
-
end
|
185
|
-
(0..5).each do |i|
|
186
|
-
tax = Fiscalizer::Tax.new
|
187
|
-
tax.base = rand(10000 * 100).to_f / 100.0
|
188
|
-
tax.rate = rand(100 * 100).to_f / 100.0
|
189
|
-
taxes_spending << tax
|
190
|
-
end
|
191
|
-
(0..5).each do |i|
|
192
|
-
tax = Fiscalizer::Tax.new
|
193
|
-
tax.base = rand(10000 * 100).to_f / 100.0
|
194
|
-
tax.rate = rand(100 * 100).to_f / 100.0
|
195
|
-
tax.name = "My Test Tax #{i}"
|
196
|
-
taxes_other << tax
|
197
|
-
end
|
198
|
-
# Generate invoice
|
199
|
-
invoice = fiscal.invoice uuid: UUID,
|
200
|
-
time_sent: Time.now,
|
201
|
-
pin: PIN,
|
202
|
-
in_vat_system: true,
|
203
|
-
time_issued: Time.now - 3600,
|
204
|
-
consistance_mark: "P",
|
205
|
-
issued_number: "1",
|
206
|
-
issued_office: "Pm2",
|
207
|
-
issued_machine: "3",
|
208
|
-
tax_vat: taxes_vat,
|
209
|
-
tax_spending: taxes_spending,
|
210
|
-
tax_other: taxes_other,
|
211
|
-
payment_method: "g",
|
212
|
-
operator_pin: PIN_OPERATOR,
|
213
|
-
subsequent_delivery: false,
|
214
|
-
value_non_taxable: 200.0
|
215
|
-
|
216
|
-
assert !invoice.errors?, "Returned an error"
|
217
|
-
assert invoice.uuid != nil, "'UUID' was not returned"
|
218
|
-
assert invoice.processed_at != nil, "'Processed at' was not returned"
|
219
|
-
assert invoice.unique_identifier != nil, "Uniqe Identifier (JIR) was not returned"
|
220
|
-
end # test_invoice
|
221
|
-
|
222
|
-
end # FiscalizerRubyTest
|
@@ -1,28 +0,0 @@
|
|
1
|
-
require "test/unit"
|
2
|
-
require "fiscalizer"
|
3
|
-
|
4
|
-
class CommunicationTest < Test::Unit::TestCase
|
5
|
-
|
6
|
-
def test_initialization
|
7
|
-
# Manual build
|
8
|
-
comm = Fiscalizer::Communication.new
|
9
|
-
assert comm, "Failed to initialize"
|
10
|
-
|
11
|
-
# Default value
|
12
|
-
assert_equal "http://www.apis-it.hr/fin/2012/types/f73", comm.tns, "Tns was not assigned by default"
|
13
|
-
assert_equal "http://www.apis-it.hr/fin/2012/types/f73 FiskalizacijaSchema.xsd", comm.schemaLocation, "Schema Location was not assigned by default"
|
14
|
-
|
15
|
-
# Manual assignment
|
16
|
-
comm.tns = "test.tns.hr"
|
17
|
-
comm.schemaLocation = "test.tns.hr/Schema.xml"
|
18
|
-
assert_equal "test.tns.hr", comm.tns, "Tns was not assigned"
|
19
|
-
assert_equal "test.tns.hr/Schema.xml", comm.schemaLocation, "Schema Location was not assigned"
|
20
|
-
|
21
|
-
# Automatic assignment
|
22
|
-
comm = nil
|
23
|
-
comm = Fiscalizer::Communication.new tns: "test.tns.hr", schemaLocation: "test.tns.hr/Schema.xml"
|
24
|
-
assert_equal "test.tns.hr", comm.tns, "Tns was not assigned"
|
25
|
-
assert_equal "test.tns.hr/Schema.xml", comm.schemaLocation, "Schema Location was not assigned"
|
26
|
-
end # test_initialization
|
27
|
-
|
28
|
-
end
|
data/test/test_invoice.rb
DELETED
data/test/test_office.rb
DELETED
data/test/test_tax.rb
DELETED
@@ -1,89 +0,0 @@
|
|
1
|
-
require "test/unit"
|
2
|
-
require "fiscalizer"
|
3
|
-
|
4
|
-
class TaxTest < Test::Unit::TestCase
|
5
|
-
|
6
|
-
def test_initialization
|
7
|
-
# Manual build
|
8
|
-
tax = Fiscalizer::Tax.new
|
9
|
-
assert tax, "Failed to initialize"
|
10
|
-
tax.base = 100
|
11
|
-
tax.rate = 25
|
12
|
-
tax.name = "My test tax"
|
13
|
-
assert_equal 100, tax.base, "Wrong base assigned"
|
14
|
-
assert_equal 25, tax.rate, "Wrong rate assigned"
|
15
|
-
assert_equal "My test tax", tax.name, "Wrong name assigned"
|
16
|
-
|
17
|
-
tax = nil
|
18
|
-
tax = Fiscalizer::Tax.new base: 100, rate: 25, name: "My test tax"
|
19
|
-
assert tax, "Failed to initialize"
|
20
|
-
assert_equal 100, tax.base, "Automatically assigned wrong base"
|
21
|
-
assert_equal 25, tax.rate, "Automatically assigned wrong rate"
|
22
|
-
assert_equal "My test tax", tax.name, "Automatically assigned worng name"
|
23
|
-
end # test_initialization
|
24
|
-
|
25
|
-
def test_rounding
|
26
|
-
# Whole numbers
|
27
|
-
tax = Fiscalizer::Tax.new base: 100, rate: 1
|
28
|
-
assert_equal 100, tax.base, "Whole number base is wrong" # 100 -> 100
|
29
|
-
assert_equal 1, tax.rate, "Whole number rate is wrong" # 1 -> 1 -> 0.01
|
30
|
-
assert_equal 1, tax.total, "Whole number total is wrong" # 100 * 0.01 = 1
|
31
|
-
assert_equal 101, tax.summed, "Whole number summed is wrong" # 100 + 1 = 101
|
32
|
-
|
33
|
-
# Decimal numbers
|
34
|
-
tax = Fiscalizer::Tax.new base: 1.5, rate: 10.5
|
35
|
-
assert_equal 1.50, tax.base, "Decimal number base is wrong" # 1.5 -> 1.5
|
36
|
-
assert_equal 10.5, tax.rate, "Decimal number rate is wrong" # 10.5 -> 10.5 -> 0.105
|
37
|
-
assert_equal 0.16, tax.total, "Decimal number total is wrong" # 1.5 * 0.105 = 0.1575
|
38
|
-
assert_equal 1.66, tax.summed, "Decimal number summed is wrong" # 1.5 + 0.16 = 1.66
|
39
|
-
|
40
|
-
# Whole decimal numbers
|
41
|
-
tax = Fiscalizer::Tax.new base: 100.0, rate: 1.0
|
42
|
-
assert_equal 100.0, tax.base, "Whole decimal number base is wrong" # 100 -> 100
|
43
|
-
assert_equal 1.000, tax.rate, "Whole decimal number rate is wrong" # 1 -> 1 -> 0.01
|
44
|
-
assert_equal 1.000, tax.total, "Whole decimal number total is wrong" # 100 * 0.01 = 1
|
45
|
-
assert_equal 101.0, tax.summed, "Whole decimal number summed is wrong" # 100 + 1 = 101
|
46
|
-
|
47
|
-
# Round down
|
48
|
-
tax = Fiscalizer::Tax.new base: 13.111992, rate: 10.10499999999
|
49
|
-
assert_equal 13.11, tax.base, "Round down number base is wrong" # 13.111992 -> 13.11
|
50
|
-
assert_equal 10.10, tax.rate, "Round down number rate is wrong" # 10.10499999999 -> 10.10 -> 0.1010
|
51
|
-
assert_equal 1.320, tax.total, "Round down number total is wrong" # 13.11 * 0.1010 = 1.32411
|
52
|
-
assert_equal 14.43, tax.summed, "Round down number summed is wrong" # 13.11 + 1.32 = 14.43
|
53
|
-
|
54
|
-
# Round up
|
55
|
-
tax = Fiscalizer::Tax.new base: 13.2450000001, rate: 25.9989541
|
56
|
-
assert_equal 13.25, tax.base, "Round up number base is wrong" # 13.2450000001 -> 13.25
|
57
|
-
assert_equal 26.00, tax.rate, "Round up number rate is wrong" # 25.9989541 -> 26 -> 0.26
|
58
|
-
assert_equal 3.450, tax.total, "Round up number total is wrong" # 13.25 * 0.26 = 3.445
|
59
|
-
assert_equal 16.70, tax.summed, "Round up number summed is wrong" # 13.25 + 3.45 = 16.7
|
60
|
-
end # test_rounding
|
61
|
-
|
62
|
-
def test_string_conversion
|
63
|
-
# Whole numbers
|
64
|
-
tax = Fiscalizer::Tax.new base: 100, rate: 1
|
65
|
-
assert_equal "100.00", tax.base_str, "Whole number base is wrong"
|
66
|
-
assert_equal "1.00", tax.rate_str, "Whole number rate is wrong"
|
67
|
-
assert_equal "1.00", tax.total_str, "Whole number total is wrong"
|
68
|
-
assert_equal "101.00", tax.summed_str, "Whole number summed is wrong"
|
69
|
-
|
70
|
-
# Decimal numbers
|
71
|
-
tax = Fiscalizer::Tax.new base: 1.5, rate: 10.5
|
72
|
-
assert_equal "1.50", tax.base_str, "Decimal number base is wrong"
|
73
|
-
assert_equal "10.50", tax.rate_str, "Decimal number rate is wrong"
|
74
|
-
assert_equal "0.16", tax.total_str, "Decimal number total is wrong"
|
75
|
-
assert_equal "1.66", tax.summed_str, "Decimal number summed is wrong"
|
76
|
-
|
77
|
-
# Whole decimal numbers
|
78
|
-
tax = Fiscalizer::Tax.new base: 100.000, rate: 1.000
|
79
|
-
assert_equal "100.00", tax.base_str, "Whole decimal number base is wrong"
|
80
|
-
assert_equal "1.00", tax.rate_str, "Whole decimal number rate is wrong"
|
81
|
-
assert_equal "1.00", tax.total_str, "Whole decimal number total is wrong"
|
82
|
-
assert_equal "101.00", tax.summed_str, "Whole decimal number summed is wrong"
|
83
|
-
end # test_string_conversion
|
84
|
-
|
85
|
-
def test_math
|
86
|
-
|
87
|
-
end # test_math
|
88
|
-
|
89
|
-
end
|