Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Include type merkle_map and mix format #67

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion lib/delta_crdt/storage.ex
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ defmodule DeltaCrdt.Storage do
@type t :: module()

@opaque storage_format ::
{node_id :: term(), sequence_number :: integer(), crdt_state :: term()}
{node_id :: term(), sequence_number :: integer(), crdt_state :: term(),
merkle_map :: term()}

@callback write(name :: term(), storage_format()) :: :ok
@callback read(name :: term()) :: storage_format() | nil
Expand Down
28 changes: 17 additions & 11 deletions test/aw_lww_map_property_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ defmodule AWLWWMapPropertyTest do

setup do
operation_gen =
ExUnitProperties.gen all op <- StreamData.member_of([:add, :remove]),
node_id <- term(),
key <- term(),
value <- term() do
ExUnitProperties.gen all(
op <- StreamData.member_of([:add, :remove]),
node_id <- term(),
key <- term(),
value <- term()
) do
{op, key, value, node_id}
end

Expand All @@ -17,9 +19,11 @@ defmodule AWLWWMapPropertyTest do

describe ".add/4" do
property "can add an element" do
check all key <- term(),
val <- term(),
node_id <- term() do
check all(
key <- term(),
val <- term(),
node_id <- term()
) do
assert %{key => val} ==
AWLWWMap.join(
AWLWWMap.compress_dots(AWLWWMap.new()),
Expand All @@ -32,7 +36,7 @@ defmodule AWLWWMapPropertyTest do
end

property "arbitrary add and remove sequence results in correct map", context do
check all operations <- list_of(context.operation_gen) do
check all(operations <- list_of(context.operation_gen)) do
actual_result =
operations
|> Enum.reduce(AWLWWMap.compress_dots(AWLWWMap.new()), fn
Expand Down Expand Up @@ -60,9 +64,11 @@ defmodule AWLWWMapPropertyTest do

describe ".remove/3" do
property "can remove an element" do
check all key <- term(),
val <- term(),
node_id <- term() do
check all(
key <- term(),
val <- term(),
node_id <- term()
) do
crdt = AWLWWMap.compress_dots(AWLWWMap.new())
crdt = AWLWWMap.join(crdt, AWLWWMap.add(key, val, node_id, crdt), [key])

Expand Down
12 changes: 7 additions & 5 deletions test/aw_lww_map_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,16 @@ defmodule NewAWLWWMapTest do

property "arbitrary add and remove sequence results in correct map" do
operation_gen =
ExUnitProperties.gen all op <- StreamData.member_of([:add, :remove]),
node_id <- term(),
key <- term(),
value <- term() do
ExUnitProperties.gen all(
op <- StreamData.member_of([:add, :remove]),
node_id <- term(),
key <- term(),
value <- term()
) do
{op, key, value, node_id}
end

check all operations <- list_of(operation_gen) do
check all(operations <- list_of(operation_gen)) do
actual_result =
operations
|> Enum.reduce(AWLWWMap.new(), fn
Expand Down
24 changes: 15 additions & 9 deletions test/support/awlww_map_property.ex
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,31 @@ defmodule AWLWWMapProperty do
alias DeltaCrdt.{AWLWWMap}

def add_operation do
ExUnitProperties.gen all key <- binary(),
val <- binary(),
node_id <- integer() do
ExUnitProperties.gen all(
key <- binary(),
val <- binary(),
node_id <- integer()
) do
fn state -> AWLWWMap.add(key, val, node_id, state) end
end
end

def remove_operation do
ExUnitProperties.gen all key <- binary(),
node_id <- integer() do
ExUnitProperties.gen all(
key <- binary(),
node_id <- integer()
) do
fn state -> AWLWWMap.remove(key, node_id, state) end
end
end

def random_operation do
ExUnitProperties.gen all operation <- one_of([:add, :remove]),
key <- binary(),
val <- binary(),
node_id <- integer() do
ExUnitProperties.gen all(
operation <- one_of([:add, :remove]),
key <- binary(),
val <- binary(),
node_id <- integer()
) do
case operation do
:add ->
fn
Expand Down