Example #1
0
func TestInterfaceEquality(t *testing.T) {
	o := js.Global.Get("Object").New()
	var i interface{} = o
	if i != o {
		t.Fail()
	}
}
Example #2
0
func Test_Statement_ActualCommand(t *testing.T) {
	withStatement(t, "SELECT id FROM table1 WHERE strreq = '@id' OR id = @id;", []*Parameter{idParameter(3)}, func(stmt *Statement) {
		if stmt.ActualCommand() != "SELECT id FROM table1 WHERE strreq = '@id' OR id = $1;" {
			t.Fail()
		}
	})
}
Example #3
0
func TestVersion(t *testing.T) {
	v := new(Version)
	v.Version = uint16(1)
	v.Timestamp = time.Unix(0, 0)
	v.IpAddress = net.ParseIP("1.2.3.4")
	v.Port = uint16(4444)
	v.UserAgent = "Hello World!"

	verBytes := v.GetBytes()
	if len(verBytes) != verLen+12 {
		fmt.Println("Incorrect Byte Length: ", verBytes)
		t.Fail()
	}

	v2 := new(Version)
	err := v2.FromBytes(verBytes)
	if err != nil {
		fmt.Println("Error Decoding: ", err)
		t.FailNow()
	}

	if v2.Version != 1 || v2.Timestamp != time.Unix(0, 0) || v2.IpAddress.String() != "1.2.3.4" || v2.Port != 4444 || v2.UserAgent != "Hello World!" {
		fmt.Println("Incorrect decoded version: ", v2)
		t.Fail()
	}
}
Example #4
0
func TestToModulePath(t *testing.T) {
	cwd, _ := os.Getwd()

	if strings.Compare(ToModuleName(cwd), "github.com/fredjeck/gobot") != 0 {
		t.Fail()
	}
}
func TestIndexesAsync_ClientWaitScenario(t *testing.T) {
	testDBWrapper.CreateFreshDB(t)
	testBlockchainWrapper := newTestBlockchainWrapper(t)
	chain := testBlockchainWrapper.blockchain
	if chain.indexer.isSynchronous() {
		t.Skip("Skipping because blockchain is configured to index block data synchronously")
	}
	blocks, _, err := testBlockchainWrapper.populateBlockChainWithSampleData()
	if err != nil {
		t.Logf("Error populating block chain with sample data: %s", err)
		t.Fail()
	}
	t.Log("Increasing size of blockchain by one artificially so as to make client wait")
	chain.size = chain.size + 1
	t.Log("Resetting size of blockchain to original and adding one block in a separate go routine so as to wake up the client")
	go func() {
		time.Sleep(2 * time.Second)
		chain.size = chain.size - 1
		blk, err := buildTestBlock(t)
		if err != nil {
			t.Logf("Error building test block: %s", err)
			t.Fail()
		}
		testBlockchainWrapper.addNewBlock(blk, []byte("stateHash"))
	}()
	t.Log("Executing client query. The client would wait and will be woken up")
	blockHash, _ := blocks[0].GetHash()
	block := testBlockchainWrapper.getBlockByHash(blockHash)
	testutil.AssertEquals(t, block, blocks[0])
}
Example #6
0
func TestGetWhenKeyIsEmptyString(t *testing.T) {
	bs := NewBlockstore(ds_sync.MutexWrap(ds.NewMapDatastore()))
	_, err := bs.Get(key.Key(""))
	if err != ErrNotFound {
		t.Fail()
	}
}
Example #7
0
func TestParsing(t *testing.T) {
	addresses := []string{
		"1DgxRTofdbau7kpf3pQeRydcoTPG2L5NUX",
		"17Nt7rWiRZKDgcNp421zZ1FHGPWSnnT1bk",
	}
	var decoder *json.Decoder
	if true {
		response, err := http.Get(url)
		if err != nil {
			t.SkipNow()
			// log.Fatal(err)
		}
		defer response.Body.Close()
		decoder = json.NewDecoder(response.Body)
	}

	r := new(OverviewReport)
	err := decoder.Decode(&r)
	if err != nil {
		t.Fail()
		// log.Fatal(err)
	}
	total := new(AddressReport)
	for _, address := range addresses {
		report, ok := r.Report[address]
		if !ok {
			t.Fail()
		}
		total.Add(report)
	}
}
Example #8
0
func TestNilAtLhs(t *testing.T) {
	type F func(string) string
	var f F
	if nil != f {
		t.Fail()
	}
}
Example #9
0
func TestAddAssignOnPackageVar(t *testing.T) {
	otherpkg.Test = 0
	otherpkg.Test += 42
	if otherpkg.Test != 42 {
		t.Fail()
	}
}
Example #10
0
func TestEncodeSeveral(t *testing.T) {
	tests := map[string][]string{
		"a":   []string{"a"},
		"axe": []string{"axe"},
		"a/b/c/d/e/f/h/g/i/j": []string{"a", "b", "c", "d", "e",
			"f", "h", "g", "i", "j"},
	}
	for p, a := range tests {
		m := &Message{Type: Confirmable, Code: GET, MessageID: 12345}
		m.SetPathString(p)
		b, err := (*m).encode()
		if err != nil {
			t.Errorf("Error encoding %#v", p)
			t.Fail()
			continue
		}
		m2, err := parseMessage(b)
		if err != nil {
			t.Fatalf("Can't parse my own message at %#v: %v", p, err)
		}

		if !reflect.DeepEqual(m2.Path(), a) {
			t.Errorf("Expected %#v, got %#v", a, m2.Path())
			t.Fail()
		}
	}
}
Example #11
0
func TestPointerEquality(t *testing.T) {
	a := 1
	b := 1
	if &a != &a || &a == &b {
		t.Fail()
	}
	m := make(map[*int]int)
	m[&a] = 2
	m[&b] = 3
	if m[&a] != 2 || m[&b] != 3 {
		t.Fail()
	}

	for {
		c := 1
		d := 1
		if &c != &c || &c == &d {
			t.Fail()
		}
		break
	}

	s := struct {
		e int
		f int
	}{1, 1}
	if &s.e != &s.e || &s.e == &s.f {
		t.Fail()
	}

	g := [3]int{1, 2, 3}
	if &g[0] != &g[0] || &g[:][0] != &g[0] || &g[:][0] != &g[:][0] {
		t.Fail()
	}
}
Example #12
0
func TestDereference(t *testing.T) {
	s := *dummys
	p := &s
	if p != dummys {
		t.Fail()
	}
}
Example #13
0
func TestNewArrayBuffer(t *testing.T) {
	b := []byte("abcd")
	a := js.NewArrayBuffer(b[1:3])
	if a.Get("byteLength").Int() != 2 {
		t.Fail()
	}
}
Example #14
0
func TestReflection(t *testing.T) {
	o := js.Global.Call("eval", "({ answer: 42 })")
	if reflect.ValueOf(o).Interface().(*js.Object) != o {
		t.Fail()
	}

	type S struct {
		Field *js.Object
	}
	s := S{o}

	v := reflect.ValueOf(&s).Elem()
	if v.Field(0).Interface().(*js.Object).Get("answer").Int() != 42 {
		t.Fail()
	}
	if v.Field(0).MethodByName("Get").Call([]reflect.Value{reflect.ValueOf("answer")})[0].Interface().(*js.Object).Int() != 42 {
		t.Fail()
	}
	v.Field(0).Set(reflect.ValueOf(js.Global.Call("eval", "({ answer: 100 })")))
	if s.Field.Get("answer").Int() != 100 {
		t.Fail()
	}

	if fmt.Sprintf("%+v", s) != "{Field:[object Object]}" {
		t.Fail()
	}
}
Example #15
0
func TestCycleTime(t *testing.T) {
	const MeasureTolerance int64 = 1000000

	var d Duration
	d.FromSec(0.01)
	r := CycleTime(d)
	if !r.actualCycleTime.IsZero() {
		t.Fail()
	}
	if r.expectedCycleTime.ToSec() != 0.01 {
		t.Fail()
	}

	start := time.Now().UnixNano()
	r.Sleep()
	end := time.Now().UnixNano()

	actual := r.CycleTime()
	elapsed := end - start
	delta := int64(actual.ToNSec()) - elapsed
	if delta < 0 {
		delta = -delta
	}
	if delta > MeasureTolerance {
		t.Error(delta)
	}
}
Example #16
0
func TestPointerOfPackageVar(t *testing.T) {
	otherpkg.Test = 42
	p := &otherpkg.Test
	if *p != 42 {
		t.Fail()
	}
}
Example #17
0
func TestRateSleep(t *testing.T) {
	// The jitter tolerance (5msec) doesn't have strong basis.
	const JitterTolerance int64 = 5000000
	ct := NewDuration(0, 100000000) // 10msec
	r := CycleTime(ct)
	if ct.Cmp(r.ExpectedCycleTime()) != 0 {
		t.Fail()
	}
	for i := 0; i < 10; i++ {
		start := time.Now().UnixNano()
		time.Sleep(time.Duration(rand.Intn(10)) * time.Millisecond)
		r.Sleep()
		end := time.Now().UnixNano()

		elapsed := end - start
		delta := elapsed - int64(ct.ToNSec())
		if delta < 0 {
			delta = -delta
		}
		if delta > JitterTolerance {
			actual := r.CycleTime()
			t.Errorf("expected: %d  actual: %d  measured: %d  delta: %d",
				ct.ToNSec(), actual.ToNSec(), elapsed, delta)
		}
	}
}
Example #18
0
func TestWrappedTypeMethod(t *testing.T) {
	i := Int(42)
	p := &i
	if p.Value() != 42 {
		t.Fail()
	}
}
Example #19
0
File: server.go Project: jbuck/rack
func Server(t *testing.T, stubs ...Http) *httptest.Server {
	ts := httptest.NewTLSServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		found := false

		for _, stub := range stubs {
			if stub.Method == r.Method && stub.Path == r.URL.Path {
				data, err := json.Marshal(stub.Response)

				if err != nil {
					w.WriteHeader(503)
					w.Write(serverError(err.Error()))
				}

				w.WriteHeader(stub.Code)
				w.Write(data)

				found = true
				break
			}
		}

		if !found {
			fmt.Fprintf(os.Stderr, "Missing HTTP stub:\n")
			fmt.Fprintf(os.Stderr, "  %s %s\n", r.Method, r.URL.Path)
			t.Fail()

			w.WriteHeader(404)
			w.Write(serverError("stub not found"))
		}
	}))

	return ts
}
func Test_Secp256_06a_alt02(t *testing.T) {
	pubkey1, seckey := _GenerateKeyPair()
	msg := RandByte(32)
	sig := _Sign(msg, seckey)

	if sig == nil {
		t.Fail()
	}
	if len(sig) != 65 {
		t.Fail()
	}
	for i := 0; i < TESTS; i++ {
		sig = randSig()
		pubkey2 := _RecoverPubkey(msg, sig)

		if bytes.Equal(pubkey1, pubkey2) == true {
			t.Fail()
		}

		if pubkey2 != nil && _VerifySignature(msg, sig, pubkey2) != 1 {
			t.Fail()
		}

		if _VerifySignature(msg, sig, pubkey1) == 1 {
			t.Fail()
		}
	}
}
Example #21
0
func TestBitMath(t *testing.T) {
	ip := "10.20.30.40"
	ip_parsed := net.ParseIP(ip)
	if ip != Inet_ntoa(Inet_aton(&ip_parsed)) {
		t.Fail()
	}
}
func Test_Deterministic_Keypairs_032(t *testing.T) {

	//test vectors: seed, seckey
	var test_array []string = []string{
		"tQ93w5Aqcunm9SGUfnmF4fJv", "9b8c3e36adce64dedc80d6dfe51ff1742cc1d755bbad457ac01177c5a18a789f",
		"DC7qdQQtbWSSaekXnFmvQgse", "d2deaf4a9ff7a5111fe1d429d6976cbde78811fdd075371a2a4449bb0f4d8bf9",
		"X8EkuUZC7Td7PAXeS7Duc7vR", "cad79b6dcf7bd21891cbe20a51c57d59689ae6e3dc482cd6ec22898ac00cd86b",
		"tVqPYHHNVPRWyEed62v7f23u", "2a386e94e9ffaa409517cbed81b9b2d4e1c5fb4afe3cbd67ce8aba11af0b02fa",
		"kCy4R57HDfLqF3pVhBWxuMcg", "26a7c6d8809c476a56f7455209f58b5ff3f16435fcf208ff2931ece60067f305",
		"j8bjv86ZNjKqzafR6mtSUVCE", "ea5c0f8c9f091a70bf38327adb9b2428a9293e7a7a75119920d759ecfa03a995",
		"qShryAzVY8EtsuD3dsAc7qnG", "331206176509bcae31c881dc51e90a4e82ec33cd7208a5fb4171ed56602017fa",
		"5FGG7ZBa8wVMBJkmzpXj5ESX", "4ea2ad82e7730d30c0c21d01a328485a0cf5543e095139ba613929be7739b52c",
		"f46TZG4xJHXUGWx8ekbNqa9F", "dcddd403d3534c4ef5703cc07a771c107ed49b7e0643c6a2985a96149db26108",
		"XkZdQJ5LT96wshN8JBH8rvEt", "3e276219081f072dff5400ca29a9346421eaaf3c419ff1474ac1c81ad8a9d6e1",
		"GFDqXU4zYymhJJ9UGqRgS8ty", "95be4163085b571e725edeffa83fff8e7a7db3c1ccab19d0f3c6e105859b5e10",
		"tmwZksH2XyvuamnddYxyJ5Lp", "2666dd54e469df56c02e82dffb4d3ea067daafe72c54dc2b4f08c4fb3a7b7e42",
		"EuqZFsbAV5amTzkhgAMgjr7W", "40c325c01f2e4087fcc97fcdbea6c35c88a12259ebf1bce0b14a4d77f075abbf",
		"TW6j8rMffZfmhyDEt2JUCrLB", "e676e0685c5d1afd43ad823b83db5c6100135c35485146276ee0b0004bd6689e",
		"8rvkBnygfhWP8kjX9aXq68CY", "21450a646eed0d4aa50a1736e6c9bf99fff006a470aab813a2eff3ee4d460ae4",
		"phyRfPDuf9JMRFaWdGh7NXPX", "ca7bc04196c504d0e815e125f7f1e086c8ae8c10d5e9df984aeab4b41bf9e398",
	}

	for i := 0; i < len(test_array)/2; i++ {
		seed := []byte(test_array[2*i+0])
		sec1 := Decode(test_array[2*i+1])

		_, sec2 := _GenerateDeterministicKeyPair(seed)
		if bytes.Equal(sec1, sec2) == false {
			t.Fail()
		}
	}
}
Example #23
0
func TestSplitDomainName(t *testing.T) {
	labels := map[string][]string{
		"miek.nl":       []string{"miek", "nl"},
		".":             nil,
		"www.miek.nl.":  []string{"www", "miek", "nl"},
		"www.miek.nl":   []string{"www", "miek", "nl"},
		"www..miek.nl":  []string{"www", "", "miek", "nl"},
		`www\.miek.nl`:  []string{`www\.miek`, "nl"},
		`www\\.miek.nl`: []string{`www\\`, "miek", "nl"},
	}
domainLoop:
	for domain, splits := range labels {
		parts := SplitDomainName(domain)
		if len(parts) != len(splits) {
			t.Logf("SplitDomainName returned %v for %s, expected %v", parts, domain, splits)
			t.Fail()
			continue domainLoop
		}
		for i := range parts {
			if parts[i] != splits[i] {
				t.Logf("SplitDomainName returned %v for %s, expected %v", parts, domain, splits)
				t.Fail()
				continue domainLoop
			}
		}
	}
}
func Test_DeterministicWallets12(t *testing.T) {

	var test_array []string = []string{
		"90c56f5b8d78a46fb4cddf6fd9c6d88d6d2d7b0ec35917c7dac12c03b04e444e", "94dd1a9de9ffd57b5516b8a7f090da67f142f7d22356fa5d1b894ee4d4fba95b",
		"a3b08ccf8cbae4955c02f223be1f97d2bb41d92b7f0c516eb8467a17da1e6057", "82fba4cc2bc29eef122f116f45d01d82ff488d7ee713f8a95c162a64097239e0",
		"7048eb8fa93cec992b93dc8e93c5543be34aad05239d4c036cf9e587bbcf7654", "44c059496aac871ac168bb6889b9dd3decdb9e1fa082442a95fcbca982643425",
		"6d25375591bbfce7f601fc5eb40e4f3dde2e453dc4bf31595d8ec29e4370cd80", "d709ceb1a6fb906de506ea091c844ca37c65e52778b8d257d1dd3a942ab367fb",
		"7214b4c09f584c5ddff971d469df130b9a3c03e0277e92be159279de39462120", "5fe4986fa964773041e119d2b6549acb392b2277a72232af75cbfb62c357c1a7",
		"b13e78392d5446ae304b5fc9d45b85f26996982b2c0c86138afdac8d2ea9016e", "f784abc2e7f11ee84b4adb72ea4730a6aabe27b09604c8e2b792d8a1a31881ac",
		"9403bff4240a5999e17e0ab4a645d6942c3a7147c7834e092e461a4580249e6e", "d495174b8d3f875226b9b939121ec53f9383bd560d34aa5ca3ac6b257512adf4",
		"2665312a3e3628f4df0b9bc6334f530608a9bcdd4d1eef174ecda99f51a6db94", "1fdc9fbfc6991b9416b3a8385c9942e2db59009aeb2d8de349b73d9f1d389374",
		"6cb37532c80765b7c07698502a49d69351036f57a45a5143e33c57c236d841ca", "c87c85a6f482964db7f8c31720981925b1e357a9fdfcc585bc2164fdef1f54d0",
		"8654a32fa120bfdb7ca02c487469070eba4b5a81b03763a2185fdf5afd756f3c", "e2767d788d1c5620f3ef21d57f2d64559ab203c044f0a5f0730b21984e77019c",
		"66d1945ceb6ef8014b1b6703cb624f058913e722f15d03225be27cb9d8aabe4a", "3fcb80eb1d5b91c491408447ac4e221fcb2254c861adbb5a178337c2750b0846",
		"22c7623bf0e850538329e3e6d9a6f9b1235350824a3feaad2580b7a853550deb", "5577d4be25f1b44487140a626c8aeca2a77507a1fc4fd466dd3a82234abb6785",
		"a5eebe3469d68c8922a1a8b5a0a2b55293b7ff424240c16feb9f51727f734516", "c07275582d0681eb07c7b51f0bca0c48c056d571b7b83d84980ab40ac7d7d720",
		"479ec3b589b14aa7290b48c2e64072e4e5b15ce395d2072a5a18b0a2cf35f3fd", "f10e2b7675dfa557d9e3188469f12d3e953c2d46dce006cd177b6ae7f465cfc0",
		"63952334b731ec91d88c54614925576f82e3610d009657368fc866e7b1efbe73", "0bcbebb39d8fe1cb3eab952c6f701656c234e462b945e2f7d4be2c80b8f2d974",
		"256472ee754ef6af096340ab1e161f58e85fb0cc7ae6e6866b9359a1657fa6c1", "88ba6f6c66fc0ef01c938569c2dd1f05475cb56444f4582d06828e77d54ffbe6",
	}

	for i := 0; i < len(test_array)/2; i++ {
		seed := Decode(test_array[2*i+0])                    //input
		seckey1 := Decode(test_array[2*i+1])                 //target
		_, _, seckey2 := _DeterministicKeyPairIterator(seed) //output
		if bytes.Equal(seckey1, seckey2) == false {
			t.Fail()
		}
	}
}
Example #25
0
func Test_Connect_InvalidPassword_ExpectConnNil(t *testing.T) {
	conn, _ := Connect("dbname=testdatabase user=testuser password=wrongpassword", LogNothing)
	if conn != nil {
		t.Fail()
		conn.Close()
	}
}
func Test_Secp256k1_Hash2(t *testing.T) {

	var test_array []string = []string{
		"90c56f5b8d78a46fb4cddf6fd9c6d88d6d2d7b0ec35917c7dac12c03b04e444e", "a70c36286be722d8111e69e910ce4490005bbf9135b0ce8e7a59f84eee24b88b",
		"a3b08ccf8cbae4955c02f223be1f97d2bb41d92b7f0c516eb8467a17da1e6057", "e9db072fe5817325504174253a056be7b53b512f1e588f576f1f5a82cdcad302",
		"7048eb8fa93cec992b93dc8e93c5543be34aad05239d4c036cf9e587bbcf7654", "5e9133e83c4add2b0420d485e1dcda5c00e283c6509388ab8ceb583b0485c13b",
		"6d25375591bbfce7f601fc5eb40e4f3dde2e453dc4bf31595d8ec29e4370cd80", "8d5579cd702c06c40fb98e1d55121ea0d29f3a6c42f5582b902ac243f29b571a",
		"7214b4c09f584c5ddff971d469df130b9a3c03e0277e92be159279de39462120", "3a4e8c72921099a0e6a4e7f979df4c8bced63063097835cdfd5ee94548c9c41a",
		"b13e78392d5446ae304b5fc9d45b85f26996982b2c0c86138afdac8d2ea9016e", "462efa1bf4f639ffaedb170d6fb8ba363efcb1bdf0c5aef0c75afb59806b8053",
		"9403bff4240a5999e17e0ab4a645d6942c3a7147c7834e092e461a4580249e6e", "68dd702ea7c7352632876e9dc2333142fce857a542726e402bb480cad364f260",
		"2665312a3e3628f4df0b9bc6334f530608a9bcdd4d1eef174ecda99f51a6db94", "5db72c31d575c332e60f890c7e68d59bd3d0ac53a832e06e821d819476e1f010",
		"6cb37532c80765b7c07698502a49d69351036f57a45a5143e33c57c236d841ca", "0deb20ec503b4c678213979fd98018c56f24e9c1ec99af3cd84b43c161a9bb5c",
		"8654a32fa120bfdb7ca02c487469070eba4b5a81b03763a2185fdf5afd756f3c", "36f3ede761aa683813013ffa84e3738b870ce7605e0a958ed4ffb540cd3ea504",
		"66d1945ceb6ef8014b1b6703cb624f058913e722f15d03225be27cb9d8aabe4a", "6bcb4819a96508efa7e32ee52b0227ccf5fbe5539687aae931677b24f6d0bbbd",
		"22c7623bf0e850538329e3e6d9a6f9b1235350824a3feaad2580b7a853550deb", "8bb257a1a17fd2233935b33441d216551d5ff1553d02e4013e03f14962615c16",
		"a5eebe3469d68c8922a1a8b5a0a2b55293b7ff424240c16feb9f51727f734516", "d6b780983a63a3e4bcf643ee68b686421079c835a99eeba6962fe41bb355f8da",
		"479ec3b589b14aa7290b48c2e64072e4e5b15ce395d2072a5a18b0a2cf35f3fd", "39c5f108e7017e085fe90acfd719420740e57768ac14c94cb020d87e36d06752",
		"63952334b731ec91d88c54614925576f82e3610d009657368fc866e7b1efbe73", "79f654976732106c0e4a97ab3b6d16f343a05ebfcc2e1d679d69d396e6162a77",
		"256472ee754ef6af096340ab1e161f58e85fb0cc7ae6e6866b9359a1657fa6c1", "387883b86e2acc153aa334518cea48c0c481b573ccaacf17c575623c392f78b2",
	}

	for i := 0; i < len(test_array)/2; i++ {
		hash1 := Decode(test_array[2*i+0]) //input
		hash2 := Decode(test_array[2*i+1]) //target
		hash3 := _Secp256k1Hash(hash1)     //output
		if bytes.Equal(hash2, hash3) == false {
			t.Fail()
		}
	}
}
Example #27
0
func TestMessage(t *testing.T) {
	log := make(chan string, 100)
	priv, x, y := encryption.CreateKey(log)
	pub := elliptic.Marshal(elliptic.P256(), x, y)
	address := encryption.GetAddress(log, x, y)

	msg := new(Message)
	msg.AddrHash = MakeHash(address)
	msg.TxidHash = MakeHash([]byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16})
	msg.Timestamp = time.Now().Round(time.Second)
	msg.Content = *encryption.Encrypt(log, pub, "Hello World!")

	mBytes := msg.GetBytes()
	if mBytes == nil {
		fmt.Println("Error Encoding Message!")
		t.FailNow()
	}

	msg2 := new(Message)
	msg2.FromBytes(mBytes)
	if string(msg2.AddrHash.GetBytes()) != string(msg.AddrHash.GetBytes()) || string(msg2.TxidHash.GetBytes()) != string(msg.TxidHash.GetBytes()) || msg2.Timestamp.Unix() != msg.Timestamp.Unix() {
		fmt.Println("Message Header incorrect: ", msg2)
		t.FailNow()
	}

	if string(encryption.Decrypt(log, priv, &msg.Content)[:12]) != "Hello World!" {
		fmt.Println("Message content incorrect: ", string(encryption.Decrypt(log, priv, &msg.Content)[:12]))
		t.Fail()
	}
}
func TestKdTree(t *testing.T) {
	positions := make([]KdElement, length)
	for i := 0; i < length; i++ {
		positions[i] = randPos()
	}

	center := mgl.Vec3{0.5, 0.5, 0.5}
	nearestPos := positions[0]
	dist := nearestPos.(MyPos).pos.Sub(center).Len()
	for i := 1; i < length; i++ {
		dist2 := positions[i].(MyPos).pos.Sub(center).Len()
		if dist2 < dist {
			dist = dist2
			nearestPos = positions[i]
		}
	}

	tree := NewTree(positions)

	nearestPosTree := tree.NearestQuery(MyPos{center}, func(kd KdElement) bool { return true })

	if nearestPos != nearestPosTree {
		t.Log(nearestPos)
		t.Log(nearestPosTree)
		t.Fail()
	}
}
Example #29
0
func TestObj(t *testing.T) {
	o := new(Obj)
	o.HashList = make([]Hash, 2, 2)

	o.HashList[0] = MakeHash([]byte{'a', 'b', 'c', 'd'})
	o.HashList[1] = MakeHash([]byte{'e', 'f', 'g', 'h'})

	o2 := new(Obj)

	oBytes := o.GetBytes()
	if len(oBytes) != 2*hashLen {
		fmt.Println("Incorrect Obj Length! ", oBytes)
		t.FailNow()
	}

	err := o2.FromBytes(oBytes)
	if err != nil {
		fmt.Println("Error while decoding obj: ", err)
		t.FailNow()
	}

	if string(o2.HashList[0].GetBytes()) != string(o.HashList[0].GetBytes()) || string(o2.HashList[1].GetBytes()) != string(o.HashList[1].GetBytes()) {
		fmt.Println("Incorrect decoding of obj: ", o2)
		t.Fail()
	}
}
Example #30
0
func TestNull(t *testing.T) {
	var null *js.Object
	dummys.Set("test", nil)
	if null != nil || dummys == nil || dummys.Get("test") != nil {
		t.Fail()
	}
}