test cases for rand

This commit is contained in:
V2Ray
2015-09-17 00:15:06 +02:00
parent a766c61dcc
commit 26c040537f
3 changed files with 78 additions and 0 deletions
+4
View File
@@ -16,6 +16,10 @@ func Assert(t *testing.T) *Assertion {
return assert
}
func (a *Assertion) Int64(value int64) *Int64Subject {
return NewInt64Subject(NewSubject(a), value)
}
func (a *Assertion) Int(value int) *IntSubject {
return NewIntSubject(NewSubject(a), value)
}
+54
View File
@@ -0,0 +1,54 @@
package unit
import (
"strconv"
)
type Int64Subject struct {
*Subject
value int64
}
func NewInt64Subject(base *Subject, value int64) *Int64Subject {
return &Int64Subject{
Subject: base,
value: value,
}
}
func (subject *Int64Subject) Named(name string) *Int64Subject {
subject.Subject.Named(name)
return subject
}
func (subject *Int64Subject) Fail(verb string, other int64) {
subject.FailWithMessage("Not true that " + subject.DisplayString() + " " + verb + " <" + strconv.FormatInt(other, 10) + ">.")
}
func (subject *Int64Subject) DisplayString() string {
return subject.Subject.DisplayString(strconv.FormatInt(subject.value, 10))
}
func (subject *Int64Subject) Equals(expectation int64) {
if subject.value != expectation {
subject.Fail("is equal to", expectation)
}
}
func (subject *Int64Subject) GreaterThan(expectation int64) {
if subject.value <= expectation {
subject.Fail("is greater than", expectation)
}
}
func (subject *Int64Subject) AtMost(expectation int64) {
if subject.value > expectation {
subject.Fail("is at most", expectation)
}
}
func (subject *Int64Subject) AtLeast(expectation int64) {
if subject.value < expectation {
subject.Fail("is at least", expectation)
}
}