Anonymous avatar Anonymous committed 210d5ab

tests

Comments (0)

Files changed (4)

   {description, "Skein hash function NIF"},
   {vsn, "0.1"},
   {modules, [
-             skerl
+             skerl,
+             hex
             ]},
   {registered, []},
   {applications, [
+%% from http://necrobious.blogspot.com/2008/03/binary-to-hex-string-back-to-binary-in.html
+
+-module(hex).
+-export([bin_to_hexstr/1,hexstr_to_bin/1]).
+
+hex(N) when N < 10 ->
+    $0+N;
+hex(N) when N >= 10, N < 16 ->
+    $a+(N-10).
+
+int(C) when $0 =< C, C =< $9 ->
+    C - $0;
+int(C) when $A =< C, C =< $F ->
+    C - $A + 10;
+int(C) when $a =< C, C =< $f ->
+    C - $a + 10.
+    
+to_hex(N) when N < 256 ->
+    [hex(N div 16), hex(N rem 16)].
+ 
+list_to_hexstr([]) -> 
+    [];
+list_to_hexstr([H|T]) ->
+    to_hex(H) ++ list_to_hexstr(T).
+
+bin_to_hexstr(Bin) ->
+    list_to_hexstr(binary_to_list(Bin)).
+
+hexstr_to_bin(S) ->
+    list_to_binary(hexstr_to_list(S)).
+
+hexstr_to_list([X,Y|T]) ->
+    [int(X)*16 + int(Y) | hexstr_to_list(T)];
+hexstr_to_list([]) ->
+    [].
 hash(Bits, Data) ->
     "NIF library not loaded".
 
-%% ===================================================================
-%% EUnit tests
-%% ===================================================================
--ifdef(TEST).
-
-basic_test() ->
-    {ok, Ref} = new(),
-    ok = init(Ref).
-
--endif.

test/skerl_tests.erl

+-module(skerl_tests).
+
+-include_lib("eunit/include/eunit.hrl").
+
+eight_bit_input_test() ->
+  ?assertEqual(
+    {ok, hex:hexstr_to_bin("42AA6BD9CA92E90EA28DF6F6F" ++
+      "2D0D9B85A2D1907EE4DC1B171ACE7EB1159BE3BD1" ++
+      "BC56586D92492B6EFF9BE03306994C65A332C4C24" ++
+      "160F46655040E558E8329")}, 
+    skerl:hash(512, <<255>>)).
+
+fivetwelve_bit_input_test() ->
+  ?assertEqual(
+    {ok, hex:hexstr_to_bin("04F96C6F61B3E237A4FA7755EE" ++
+      "4ACF34494222968954F495AD147A1A715F7A73EBECFA1EF" ++
+      "275BED87DC60BD1A0BC602106FA98F8E7237BD1AC0958E7" ++
+      "6D306678")},
+    skerl:hash(512, hex:hexstr_to_bin("FFFEFDFCFBFAF9F" ++
+      "8F7F6F5F4F3F2F1F0EFEEEDECEBEAE9E8E7E6E5E4E3E2E1" ++
+      "E0DFDEDDDCDBDAD9D8D7D6D5D4D3D2D1D0CFCECDCCCBCAC" ++
+      "9C8C7C6C5C4C3C2C1C0"))).
+      
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.