Skip to content

Commit

Permalink
Adjust format and range of the range values
Browse files Browse the repository at this point in the history
  • Loading branch information
NelsonVides committed Mar 5, 2024
1 parent 1792240 commit 67a0941
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/coordinator/amoc_coordinator.erl
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@

-type coordination_actions() :: [action()] | action().

-type num_of_users() :: pos_integer() | {pos_integer(), pos_integer()} | all.
-type num_of_users() :: pos_integer() | {Min :: pos_integer(), Max :: pos_integer()} | all.

-type coordination_item() :: {num_of_users(), coordination_actions()}.

Expand Down Expand Up @@ -168,7 +168,7 @@ normalize_coordination_item({NoOfUsers, Actions}) when ?IS_N_OF_USERS(NoOfUsers)
normalize_coordination_item({{Min, Max}, Actions}) when ?IS_POS_INT(Min), ?IS_POS_INT(Max),
Max > Min, is_list(Actions) ->
[assert_action({Min, Max}, A) || A <- Actions],
{{Min, Max - Min}, Actions}.
{{Min, Max}, Actions}.

assert_action(all, Action) when is_function(Action, 1);
is_function(Action, 2) ->
Expand Down
6 changes: 3 additions & 3 deletions src/coordinator/amoc_coordinator_worker.erl
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
-type action() :: amoc_coordinator:action().
-type data() :: amoc_coordinator:data().

-record(state, {configured = all :: {pos_integer(), pos_integer()} | pos_integer() | all,
-record(state, {configured = all :: amoc_coordinator:num_of_users(),
required_n = all :: pos_integer() | all,
n = 0 :: non_neg_integer(),
actions = [] :: [action()],
Expand Down Expand Up @@ -131,8 +131,8 @@ safe_executions(Fun, Args) ->
end.

-spec calculate_n(amoc_coordinator:num_of_users()) -> all | pos_integer().
calculate_n({Min, Diff}) ->
Min + rand:uniform(Diff);
calculate_n({Min, Max}) ->
Min - 1 + rand:uniform(Max - Min);
calculate_n(Value) ->
Value.

Expand Down
2 changes: 1 addition & 1 deletion test/amoc_coordinator_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ execute_with_range_without_timeout(_Config) ->

History = meck:history(?MOCK_MOD),
NumOfEvents = length(History),
?assert(3 =< NumOfEvents andalso NumOfEvents =< 6),
?assert(3 =< NumOfEvents andalso NumOfEvents =< 5),

nothing_after_tags(History, [all]),
assert_telemetry_events(Name, [start, {N, add}, stop]).
Expand Down

0 comments on commit 67a0941

Please sign in to comment.