aboutsummaryrefslogtreecommitdiffstats
path: root/t/100-increment-decrement.t
blob: a7927eae09d5a981e20030df25c89563005f6db2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
#!/usr/bin/env perl -w

use strict;

use Test::More;

use lib './';
use incdec;

is(
	incdec::incdec('test 12', 1),
	'test 13',
	'increments an integer'
);

is(
	incdec::incdec('test 12 0', 1),
	'test 13 0',
	'increments the first integer'
);

is(
	incdec::incdec('test 12 0', 1, 6),
	'test 13 0',
	'increments the first integer with point at position 6'
);

is(
	incdec::incdec('test 19 0', 1, 6),
	'test 20 0',
	'increments the first integer with point at position 6'
);

is(
	incdec::incdec('test 12 0', 1, 7),
	'test 12 1',
	'increments the second integer with point at position 7'
);

is(
	incdec::incdec('test 12 19 555', 1, 9),
	'test 12 20 555',
	'increments the second double-digit integer with point at position 9'
);

is(
	incdec::incdec('test 12 19 555', 1, 12),
	'test 12 19 556',
	'increments the third triple-digit integer with point at position 12'
);

is(
	incdec::incdec('test 12 19 555', 7, 9),
	'test 12 26 555',
	'increments the second double-digit integer by 7 with point at position 9'
);

is(
	incdec::incdec('test 12 19 555 64', 1, 16),
	'test 12 19 555 65',
	'increments the fourth double-digit integer with point at position 16'
);

is(
	incdec::incdec('test 12 19 555 64', 1, 17, 1),
	'test 12 19 555 65',
	'increments the fourth double-digit integer with point at position 17 backward'
);

is(
	incdec::incdec('test 12 19 555 64', 1, 13, 1),
	'test 12 19 556 64',
	'increments the third triple-digit integer with point at position 13 backward'
);

is(
	incdec::incdec('test 12 19 555 64', 1, 14, 1),
	'test 12 19 556 64',
	'increments the third triple-digit integer with point at position 14 backward'
);

is(
	incdec::incdec('test 12 982 4 ', 1, 14, 1),
	'test 12 982 5 ',
	'increments the third integer with point at position 14 backward'
);

is(
	incdec::incdec('test -1 ', 1, 7, 1),
	'test 0 ',
	'increments the negative integer with point at position 7 backward'
);

is(
	incdec::incdec('test -1 ', -1, 7, 1),
	'test -2 ',
	'decrements the negative integer with point at position 7 backward'
);

is(
	incdec::incdec('test 1 -2', 1, 8, 1),
	'test 1 -1',
	'increments the second negative integer with point at position 8 backward'
);

is(
	incdec::incdec('test 1 -2', -1, 8, 1),
	'test 1 -3',
	'decrements the second negative integer with point at position 8 backward'
);

is(
	incdec::incdec('test 12', -1),
	'test 11',
	'decrements the first integer'
);

is(
	incdec::incdec('test 12', -1, 7, 1),
	'test 11',
	'decrements the first integer with point at position 7 backward'
);

is(
	incdec::incdec('test 12 982 4', -1, 11, 1),
	'test 12 981 4',
	'decrements the second integer with point at position 11 backward'
);

is(
	incdec::incdec('test 12 982 4', -1, 9, 1),
	'test 12 981 4',
	'decrements the second integer with point at position 9 backward'
);

is(
	incdec::incdec('test 12 982 4', -5, 8, 1),
	'test 12 977 4',
	'decrements the second integer by 5 with point at position 8 backward'
);

is(
	incdec::incdec('test 12 1 4', -2, 9, 1),
	'test 12 -1 4',
	'decrements the second integer by 2 with point at position 9 backward'
);

done_testing;