diff options
author | obscuren <geffobscura@gmail.com> | 2015-04-18 21:14:56 +0800 |
---|---|---|
committer | obscuren <geffobscura@gmail.com> | 2015-04-18 21:14:56 +0800 |
commit | ff67fbf96448b83b778960a6c20ea8dfd854c825 (patch) | |
tree | 557b494fb21eb3bad72121e82320cb158b00f93a /whisper/topic_test.go | |
parent | 8244825bbf9ca7342c052508f50a56b16c979a1e (diff) | |
parent | 525cefa37aafbc42de8911344c9853d950c06ded (diff) | |
download | dexon-ff67fbf96448b83b778960a6c20ea8dfd854c825.tar dexon-ff67fbf96448b83b778960a6c20ea8dfd854c825.tar.gz dexon-ff67fbf96448b83b778960a6c20ea8dfd854c825.tar.bz2 dexon-ff67fbf96448b83b778960a6c20ea8dfd854c825.tar.lz dexon-ff67fbf96448b83b778960a6c20ea8dfd854c825.tar.xz dexon-ff67fbf96448b83b778960a6c20ea8dfd854c825.tar.zst dexon-ff67fbf96448b83b778960a6c20ea8dfd854c825.zip |
Merge branch 'develop' into downloader-proto
Diffstat (limited to 'whisper/topic_test.go')
-rw-r--r-- | whisper/topic_test.go | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/whisper/topic_test.go b/whisper/topic_test.go new file mode 100644 index 000000000..4015079dc --- /dev/null +++ b/whisper/topic_test.go @@ -0,0 +1,67 @@ +package whisper + +import ( + "bytes" + "testing" +) + +var topicCreationTests = []struct { + data []byte + hash [4]byte +}{ + {hash: [4]byte{0xc5, 0xd2, 0x46, 0x01}, data: nil}, + {hash: [4]byte{0xc5, 0xd2, 0x46, 0x01}, data: []byte{}}, + {hash: [4]byte{0x8f, 0x9a, 0x2b, 0x7d}, data: []byte("test name")}, +} + +func TestTopicCreation(t *testing.T) { + // Create the topics individually + for i, tt := range topicCreationTests { + topic := NewTopic(tt.data) + if bytes.Compare(topic[:], tt.hash[:]) != 0 { + t.Errorf("binary test %d: hash mismatch: have %v, want %v.", i, topic, tt.hash) + } + } + for i, tt := range topicCreationTests { + topic := NewTopicFromString(string(tt.data)) + if bytes.Compare(topic[:], tt.hash[:]) != 0 { + t.Errorf("textual test %d: hash mismatch: have %v, want %v.", i, topic, tt.hash) + } + } + // Create the topics in batches + binaryData := make([][]byte, len(topicCreationTests)) + for i, tt := range topicCreationTests { + binaryData[i] = tt.data + } + textualData := make([]string, len(topicCreationTests)) + for i, tt := range topicCreationTests { + textualData[i] = string(tt.data) + } + + topics := NewTopics(binaryData...) + for i, tt := range topicCreationTests { + if bytes.Compare(topics[i][:], tt.hash[:]) != 0 { + t.Errorf("binary batch test %d: hash mismatch: have %v, want %v.", i, topics[i], tt.hash) + } + } + topics = NewTopicsFromStrings(textualData...) + for i, tt := range topicCreationTests { + if bytes.Compare(topics[i][:], tt.hash[:]) != 0 { + t.Errorf("textual batch test %d: hash mismatch: have %v, want %v.", i, topics[i], tt.hash) + } + } +} + +func TestTopicSetCreation(t *testing.T) { + topics := make([]Topic, len(topicCreationTests)) + for i, tt := range topicCreationTests { + topics[i] = NewTopic(tt.data) + } + set := newTopicSet(topics) + for i, tt := range topicCreationTests { + topic := NewTopic(tt.data) + if _, ok := set[topic.String()]; !ok { + t.Errorf("topic %d: not found in set", i) + } + } +} |