aboutsummaryrefslogtreecommitdiffstats
path: root/rlp_test.go
blob: 68676d0305177e7950f4d40781107da28f5f23f6 (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
43
44
45
46
47
48
49
50
51
52
53
54
package main

import (
  "testing"
  "fmt"
)

func TestEncode(t *testing.T) {
  strRes := "Cdog"

  bytes := Encode("dog")

  str := string(bytes)
  if str != strRes {
    t.Error(fmt.Sprintf("Expected %q, got %q", strRes, str))
  }
  //dec,_ := Decode(bytes, 0)

  sliceRes := "\x83CdogCgodCcat"
  strs := []string{"dog", "god", "cat"}
  bytes = Encode(strs)
  slice := string(bytes)
  if slice != sliceRes {
    t.Error(fmt.Sprintf("Expected %q, got %q", sliceRes, slice))
  }

  //dec,_ = Decode(bytes, 0)
}

func TestMultiEncode(t *testing.T) {
  inter := []interface{}{
    []interface{}{
      "1","2","3",
    },
    []string{
      "string",
      "string2",
      "\x86A0J1234567890A\x00B20A0\x82F395843F657986",
      "\x86A0J1234567890A\x00B20A0\x8cF395843F657986I335612448F524099H16716881A0H13114947G2039362G1507139H16719697G1048387E65360",
    },
    "test",
  }

  bytes := Encode(inter)

  Decode(bytes, 0)
}

func BenchmarkEncodeDecode(b *testing.B) {
  for i := 0; i < b.N; i++ {
    bytes := Encode([]string{"dog", "god", "cat"})
    Decode(bytes, 0)
  }
}