File: bignum_test.go

package info (click to toggle)
golang-github-twstrike-otr3 0.0~git20161015.0.744856d-3.1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, forky, sid, trixie
  • size: 1,080 kB
  • sloc: ansic: 127; makefile: 76
file content (38 lines) | stat: -rw-r--r-- 1,038 bytes parent folder | download | duplicates (3)
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
package sexp

import (
	"bufio"
	"bytes"
	"math/big"
	"testing"
)

func Test_BigNum_First_generatesAPanic(t *testing.T) {
	defer checkForPanic(t, "not valid to call First on a BigNum")
	NewBigNum("ABCD").First()
}

func Test_BigNum_Second_generatesAPanic(t *testing.T) {
	defer checkForPanic(t, "not valid to call Second on a BigNum")
	NewBigNum("ABCD").Second()
}

func Test_BigNum_String_generatesAValidRepresentation(t *testing.T) {
	res := NewBigNum("ABCD").String()
	assertEquals(t, res, "#ABCD#")
}

func Test_BigNum_Value_returnsTheBigNumInside(t *testing.T) {
	res := NewBigNum("ABCD").Value().(*big.Int)
	assertDeepEquals(t, res, new(big.Int).SetBytes([]byte{0xAB, 0xCD}))
}

func Test_ReadBigNum_returnsNilIfAskedToReadNonBigNum(t *testing.T) {
	res := ReadBigNum(bufio.NewReader(bytes.NewReader([]byte(""))))
	assertEquals(t, res, nil)
}

func Test_ReadBigNum_returnsNilIfAskedToReadBigNumThatDoesntEndCorrectly(t *testing.T) {
	res := ReadBigNum(bufio.NewReader(bytes.NewReader([]byte("#ABCD"))))
	assertEquals(t, res, nil)
}