<commit_before>-module(oprga_test).

-export([confirm/0]).

-include_lib("eunit/include/eunit.hrl").
-define(HARNESS, (rt_config:get(rt_harness))).

confirm() ->
    [Nodes] = rt:build_clusters([3]),
    lager:info("Nodes: ~p", [Nodes]),
    empty_test(Nodes),
    add_test(Nodes),
    remove_test(Nodes),
    rt:clean_cluster(Nodes),
    pass.

empty_test(Nodes) ->
    FirstNode = hd(Nodes),
    lager:info("Empty test started"),
    Type = crdt_rga,
    Key = key_empty,
    Result0 = rpc:call(FirstNode, antidote, read, [Key, Type]),
    ?assertMatch({ok, []}, Result0),
    lager:info("Empty test OK").

add_test(Nodes) ->
    FirstNode = hd(Nodes),
    lager:info("Add test started"),
    Type = crdt_rga,
    Key = key_add,
    Result0 = rpc:call(FirstNode, antidote, clocksi_execute_tx,
        [[{update, Key, Type, {{addRight, a, 1}, ucl}}]]),
    ?assertMatch({ok, _}, Result0),
    Result1 = rpc:call(FirstNode, antidote, read, [Key, Type]),
    ?assertMatch({ok, [{ok, a, _}]}, Result1),
    Result2 = rpc:call(FirstNode, antidote, clocksi_execute_tx,
        [[{update, Key, Type, {{addRight, b, 1}, ucl}}]]),
    ?assertMatch({ok, _}, Result2),
    Result3 = rpc:call(FirstNode, antidote, read, [Key, Type]),
    ?assertMatch({ok, [{ok, a, _}, {ok, b, _}]}, Result3),
    Result4 = rpc:call(FirstNode, antidote, clocksi_execute_tx,
        [[{update, Key, Type, {{addRight, c, 2}, ucl}}]]),
    ?assertMatch({ok, _}, Result4),
    Result5 = rpc:call(FirstNode, antidote, read, [Key, Type]),
    ?assertMatch({ok, [{ok, a, _}, {ok, b, _}, {ok, c, _}]}, Result5),
    lager:info("Add test OK").


remove_test(Nodes) ->
    FirstNode = hd(Nodes),
    lager:info("Remove test started"),
    Type = crdt_rga,
    Key = key_remove,
    Result0 = rpc:call(FirstNode, antidote, clocksi_execute_tx,
        [[{update, Key, Type, {{addRight, a, 1}, ucl}},
            {update, Key, Type, {{addRight, b, 1}, ucl}},
            {update, Key, Type, {{addRight, c, 2}, ucl}}]]),
    ?assertMatch({ok, _}, Result0),
    Result1 = rpc:call(FirstNode, antidote, read, [Key, Type]),
    ?assertMatch({ok, [{ok, a, _}, {ok, b, _}, {ok, c, _}]}, Result1),
    Result2 = rpc:call(FirstNode, antidote, clocksi_execute_tx,
        [[{update, Key, Type, {{remove, 2}, ucl}}]]),
    ?assertMatch({ok, _}, Result2),
    Result3 = rpc:call(FirstNode, antidote, read, [Key, Type]),
    ?assertMatch({ok, [{ok, a, _}, {deleted, b, _}, {ok, c, _}]}, Result3),
    Result4 = rpc:call(FirstNode, antidote, clocksi_execute_tx,
        [[{update, Key, Type, {{remove, 1}, ucl}}, {update, Key, Type, {{remove, 3}, ucl}}]]),
    ?assertMatch({ok, _}, Result4),
    Result5 = rpc:call(FirstNode, antidote, read, [Key, Type]),
    ?assertMatch({ok, [{deleted, a, _}, {deleted, b, _}, {deleted, c, _}]}, Result5),
    lager:info("Remove test OK").<commit_msg>insert after a remove test<commit_after>-module(oprga_test).

-export([confirm/0]).

-include_lib("eunit/include/eunit.hrl").
-define(HARNESS, (rt_config:get(rt_harness))).

confirm() ->
    [Nodes] = rt:build_clusters([3]),
    lager:info("Nodes: ~p", [Nodes]),
    empty_test(Nodes),
    add_test(Nodes),
    remove_test(Nodes),
    insert_after_remove_test(Nodes),
    rt:clean_cluster(Nodes),
    pass.

empty_test(Nodes) ->
    FirstNode = hd(Nodes),
    lager:info("Empty test started"),
    Type = crdt_rga,
    Key = key_empty,
    Result0 = rpc:call(FirstNode, antidote, read, [Key, Type]),
    ?assertMatch({ok, []}, Result0),
    lager:info("Empty test OK").

add_test(Nodes) ->
    FirstNode = hd(Nodes),
    lager:info("Add test started"),
    Type = crdt_rga,
    Key = key_add,
    Result0 = rpc:call(FirstNode, antidote, clocksi_execute_tx,
        [[{update, Key, Type, {{addRight, a, 1}, ucl}}]]),
    ?assertMatch({ok, _}, Result0),
    Result1 = rpc:call(FirstNode, antidote, read, [Key, Type]),
    ?assertMatch({ok, [{ok, a, _}]}, Result1),
    Result2 = rpc:call(FirstNode, antidote, clocksi_execute_tx,
        [[{update, Key, Type, {{addRight, b, 1}, ucl}}]]),
    ?assertMatch({ok, _}, Result2),
    Result3 = rpc:call(FirstNode, antidote, read, [Key, Type]),
    ?assertMatch({ok, [{ok, a, _}, {ok, b, _}]}, Result3),
    Result4 = rpc:call(FirstNode, antidote, clocksi_execute_tx,
        [[{update, Key, Type, {{addRight, c, 2}, ucl}}]]),
    ?assertMatch({ok, _}, Result4),
    Result5 = rpc:call(FirstNode, antidote, read, [Key, Type]),
    ?assertMatch({ok, [{ok, a, _}, {ok, b, _}, {ok, c, _}]}, Result5),
    lager:info("Add test OK").


remove_test(Nodes) ->
    FirstNode = hd(Nodes),
    lager:info("Remove test started"),
    Type = crdt_rga,
    Key = key_remove,
    Result0 = rpc:call(FirstNode, antidote, clocksi_execute_tx,
        [[{update, Key, Type, {{addRight, a, 1}, ucl}},
            {update, Key, Type, {{addRight, b, 1}, ucl}},
            {update, Key, Type, {{addRight, c, 2}, ucl}}]]),
    ?assertMatch({ok, _}, Result0),
    Result1 = rpc:call(FirstNode, antidote, read, [Key, Type]),
    ?assertMatch({ok, [{ok, a, _}, {ok, b, _}, {ok, c, _}]}, Result1),
    Result2 = rpc:call(FirstNode, antidote, clocksi_execute_tx,
        [[{update, Key, Type, {{remove, 2}, ucl}}]]),
    ?assertMatch({ok, _}, Result2),
    Result3 = rpc:call(FirstNode, antidote, read, [Key, Type]),
    ?assertMatch({ok, [{ok, a, _}, {deleted, b, _}, {ok, c, _}]}, Result3),
    Result4 = rpc:call(FirstNode, antidote, clocksi_execute_tx,
        [[{update, Key, Type, {{remove, 1}, ucl}}, {update, Key, Type, {{remove, 3}, ucl}}]]),
    ?assertMatch({ok, _}, Result4),
    Result5 = rpc:call(FirstNode, antidote, read, [Key, Type]),
    ?assertMatch({ok, [{deleted, a, _}, {deleted, b, _}, {deleted, c, _}]}, Result5),
    lager:info("Remove test OK").

insert_after_remove_test(Nodes) ->
    FirstNode = hd(Nodes),
    lager:info("Remove-Insert test started"),
    Type = crdt_rga,
    Key = key_remove_insert,
    Result0 = rpc:call(FirstNode, antidote, clocksi_execute_tx,
        [[{update, Key, Type, {{addRight, a, 1}, ucl}},
            {update, Key, Type, {{addRight, b, 1}, ucl}},
            {update, Key, Type, {{addRight, c, 2}, ucl}}]]),
    ?assertMatch({ok, _}, Result0),
    Result1 = rpc:call(FirstNode, antidote, clocksi_execute_tx,
        [[{update, Key, Type, {{remove, 3}, ucl}}]]),
    ?assertMatch({ok, _}, Result1),
    Result2 = rpc:call(FirstNode, antidote, clocksi_execute_tx,
        [[{update, Key, Type, {{addRight, d, 3}, ucl}}]]),
    ?assertMatch({ok, _}, Result2),
    Result3 = rpc:call(FirstNode, antidote, read, [Key, Type]),
    ?assertMatch({ok, [{ok, a, _}, {ok, b, _}, {deleted, c, _}, {ok, d, _}]}, Result3),
    lager:info("Remove-Insert test OK").
{'fraction_non_alphanumeric': 0.2048048048048048, 'fraction_numerical': 0.013063063063063063, 'mean_word_length': 3.8870139398385914, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 12, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6685112', 'n_tokens_mistral': 2556, 'n_tokens_neox': 2505, 'n_words': 559}