blob: bd20c393569cc29fc7a7ea3c7325bf12895c380a (
plain) (
blame)
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
|
// Copyright © 2022 siddharth ravikumar <s@ricketyspace.net>
// SPDX-License-Identifier: ISC
package lib
import "testing"
func TestStrToNum(t *testing.T) {
// Test 1
s1 := "29283329"
n1, err := StrToNum(s1)
if err != nil {
t.Errorf("test 1 failed: %v\n", err)
}
if n1 != 29283329 {
t.Errorf("test 1 failed: %v != %v\n", s1, n1)
}
// Test 2
s2 := "-83729282"
n2, err := StrToNum(s2)
if err != nil {
t.Errorf("test 2 failed: %v\n", err)
}
if n2 != -83729282 {
t.Errorf("test 2 failed: %v != %v\n", s2, n2)
}
// Test 3
s3 := "887232.2323"
_, err = StrToNum(s3)
if err == nil {
t.Errorf("test 3 failed\n")
}
// Test 4
s4 := "332e323"
_, err = StrToNum(s4)
if err == nil {
t.Errorf("test 4 failed\n")
}
}
|