diff options
author | Alex Auvolat <alex@adnab.me> | 2018-07-20 15:15:05 +0200 |
---|---|---|
committer | Alex Auvolat <alex@adnab.me> | 2018-07-20 15:15:05 +0200 |
commit | a624a8504c722a2c561ce147f64c2a1a0bb6f4b0 (patch) | |
tree | ec179769d2cbc3a299ad064c3d46d7e5d17004b8 /test/mst_test.exs | |
parent | 8e77ababa95035e65fddbc8e331d62ceb7ab4507 (diff) | |
download | shard-a624a8504c722a2c561ce147f64c2a1a0bb6f4b0.tar.gz shard-a624a8504c722a2c561ce147f64c2a1a0bb6f4b0.zip |
Merkle search tree
Diffstat (limited to 'test/mst_test.exs')
-rw-r--r-- | test/mst_test.exs | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/test/mst_test.exs b/test/mst_test.exs new file mode 100644 index 0000000..68886c7 --- /dev/null +++ b/test/mst_test.exs @@ -0,0 +1,35 @@ +defmodule ShardTest.MST do + use ExUnit.Case + alias SData.MerkleSearchTree, as: MST + doctest Shard.Application + + test "merkle search tree 1" do + y = Enum.reduce(0..1000, MST.new(), + fn i, acc -> MST.insert(acc, i, i) end) + + + z = Enum.reduce(Enum.shuffle(0..1000), MST.new(), + fn i, acc -> MST.insert(acc, i, i) end) + + IO.puts "y.root: #{y.root|>Base.encode16}" + IO.puts "z.root: #{z.root|>Base.encode16}" + assert y.root == z.root + end + + test "merkle search tree 2" do + items = for i <- 0..1000 do + h = SData.term_hash i + {h, SData.term_hash h} + end + + y = Enum.reduce(items, MST.new(), + fn {k, v}, acc -> MST.insert(acc, k, v) end) + + z = Enum.reduce(Enum.shuffle(items), MST.new(), + fn {k, v}, acc -> MST.insert(acc, k, v) end) + + IO.puts "y.root: #{y.root|>Base.encode16}" + IO.puts "z.root: #{z.root|>Base.encode16}" + assert y.root == z.root + end +end |