Permalink
Browse files

add test-sample program.

  • Loading branch information...
1 parent cef40ce commit 1bc6281ddccca23ad488c5582cecbce5873ee41e @fbzhong committed May 7, 2011
Showing with 53 additions and 2 deletions.
  1. +1 −1 .gitignore
  2. +7 −0 test-sample/Makefile
  3. +32 −0 test-sample/main.cc
  4. +13 −1 test.js
View
@@ -1,4 +1,4 @@
.DS_Store
.lock-wscript
build
-
+a.out
@@ -0,0 +1,7 @@
+all: build test
+
+build:
+ g++ -o a.out -L/usr/local/lib -lcityhash main.cc
+
+test:
+ ./a.out
View
@@ -0,0 +1,32 @@
+#include <iostream>
+#include <city.h>
+#include <citycrc.h>
+
+int main (int argc, const char * argv[])
+{
+
+ // insert code here...
+ std::cout << "Hello, World!\n";
+
+ std::cout << "CityHash64(\"Hello\") : " << CityHash64("Hello", strlen("Hello")) << std::endl;
+
+ uint128 hash;
+
+ hash = CityHash128("Hello", strlen("Hello"));
+ std::cout << "CityHash128(\"Hello\") : " << hash.first << "," << hash.second << std::endl;
+
+ hash = CityHash128("hello", strlen("hello"));
+ std::cout << "CityHash128(\"hello\") : " << hash.first << "," << hash.second << std::endl;
+
+ uint128 seed;
+ seed.first = 12343;
+ seed.second = 30293;
+ hash = CityHash128WithSeed("Hello", strlen("Hello"), seed);
+ std::cout << "CityHash128WithSeed(\"Hello\") : " << hash.first << "," << hash.second << std::endl;
+
+ hash = CityHashCrc128("Hello", strlen("Hello"));
+ std::cout << "CityHashCrc128(\"Hello\") : " << hash.first << "," << hash.second << std::endl;
+
+ return 0;
+}
+
View
@@ -1,17 +1,25 @@
var cityhash = require('./build/default/cityhash.node');
+var passed = true;
+
function assertEqual(expected, actual, message) {
if(expected != actual) {
if(message) {
message += '. ';
} else {
message = '';
}
-
+ passed = false;
console.log('[Error]' + message + 'Expected ' + expected + ' , but actual is ' + actual);
}
}
+function end() {
+ if(passed) {
+ console.log('All tests are passed.');
+ }
+}
+
assertEqual('6596376470467341850', cityhash.hash64('Hello'), 'Hash64 for "Hello"');
assertEqual('2578220239953316063', cityhash.hash64('hello'), 'Hash64 for "hello"');
assertEqual('15738392108067291633', cityhash.hash64('Hello', 87392039), 'Hash64 for "hello" with seed 87392039');
@@ -20,3 +28,7 @@ assertEqual('16267654833214665223', cityhash.hash64('Hello', 87392039, 1230234),
assertEqual('9138004313465017137,12242971252332641544', cityhash.hash128('Hello'), 'Hash128 for "Hello"');
assertEqual('13523890104784088047,17404193039403234796', cityhash.hash128('hello'), 'Hash128 for "hello"');
assertEqual('15779891233746910938,15118107765960464233', cityhash.hash128('Hello', '12343,30293'), 'Hash128 for "Hello" with seed 12343,30293');
+
+assertEqual('9138004313465017137,12242971252332641544', cityhash.crc128('Hello'), 'Crc128 for "Hello"');
+
+end();

0 comments on commit 1bc6281

Please sign in to comment.