-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathfloat_test.go
68 lines (53 loc) · 1.62 KB
/
float_test.go
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
// Copyright 2014 SteelSeries ApS. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// This package implements a basic LISP interpretor for embedding in a go program for scripting.
// This file tests the integer type.
package golisp
import (
. "gopkg.in/check.v1"
)
type FloatAtomSuite struct {
n *Data
neg *Data
zero *Data
}
var _ = Suite(&FloatAtomSuite{})
func (s *FloatAtomSuite) SetUpTest(c *C) {
s.n = FloatWithValue(5.3)
s.neg = FloatWithValue(-12.345)
s.zero = FloatWithValue(0.0)
}
func (s *FloatAtomSuite) TestFloatValue(c *C) {
c.Assert(FloatValue(s.n), Equals, float32(5.3))
}
func (s *FloatAtomSuite) TestFloatValueOfNil(c *C) {
c.Assert(FloatValue(nil), Equals, float32(0.0))
}
func (s *FloatAtomSuite) TestFloatValueOfNonFloat(c *C) {
c.Assert(FloatValue(StringWithValue("3.2")), Equals, float32(0.0))
}
func (s *FloatAtomSuite) TestNegativeFloatValue(c *C) {
c.Assert(FloatValue(s.neg), Equals, float32(-12.345))
}
func (s *FloatAtomSuite) TestString(c *C) {
c.Assert(String(s.n), Equals, "5.3")
}
func (s *FloatAtomSuite) TestNegativeString(c *C) {
c.Assert(String(s.neg), Equals, "-12.345")
}
func (s *FloatAtomSuite) TestEval(c *C) {
n, err := Eval(s.n, Global)
c.Assert(err, IsNil)
c.Assert(n, Equals, s.n)
}
func (s *FloatAtomSuite) TestNegativeEval(c *C) {
n, err := Eval(s.neg, Global)
c.Assert(err, IsNil)
c.Assert(n, Equals, s.neg)
}
func (s *FloatAtomSuite) TestBooleanValue(c *C) {
c.Assert(BooleanValue(s.n), Equals, true)
c.Assert(BooleanValue(s.neg), Equals, true)
c.Assert(BooleanValue(s.zero), Equals, true)
}