Sha256: 3373a0c9a57f9f1544f7b3a36fc1635521b4f3801d8805a4faa07620ed6daee2

Contents?: true

Size: 1.84 KB

Versions: 194

Compression:

Stored size: 1.84 KB

Contents

-module( circular_buffer_tests ).

-define(TESTED_MODULE, (sut(circular_buffer))).
-define(TEST_VERSION, 1).
-include("exercism.hrl").


create_test() ->
  Pid = ?TESTED_MODULE:create( 5 ),
  ?assert( {ok, 5} =:= ?TESTED_MODULE:size(Pid) ).

write_read_test() ->
  Pid = ?TESTED_MODULE:create( 4 ),
  ?assert( {error, empty} =:= ?TESTED_MODULE:read(Pid) ),
  ?TESTED_MODULE:write( Pid, 1 ),
  ?assert( {ok, 1} =:= ?TESTED_MODULE:read(Pid) ).

write_read_many_test() ->
  Pid = ?TESTED_MODULE:create( 3 ),
  ?TESTED_MODULE:write( Pid, 1 ),
  ?TESTED_MODULE:write( Pid, 2 ),
  ?TESTED_MODULE:write( Pid, 3 ),
  ?assert( {ok, 1} =:= ?TESTED_MODULE:read(Pid) ),
  ?assert( {ok, 2} =:= ?TESTED_MODULE:read(Pid) ),
  ?assert( {ok, 3} =:= ?TESTED_MODULE:read(Pid) ).

over_write_read_test() ->
  Pid = ?TESTED_MODULE:create( 2 ),
  ?TESTED_MODULE:write( Pid, 1 ),
  ?TESTED_MODULE:write( Pid, 2 ),
  ?TESTED_MODULE:write( Pid, 3 ),
  ?TESTED_MODULE:write( Pid, 4 ),
  ?assert( {ok, 3} =:= ?TESTED_MODULE:read(Pid) ),
  ?assert( {ok, 4} =:= ?TESTED_MODULE:read(Pid) ),
  ?assert( {error, empty} =:= ?TESTED_MODULE:read(Pid) ).

write_attempt_test() ->
  Pid = ?TESTED_MODULE:create( 1 ),
  Attempt1 = ?TESTED_MODULE:write_attempt( Pid, 1 ),
  ?assert( ok =:= Attempt1 ),
  Attempt2 = ?TESTED_MODULE:write_attempt( Pid, 2 ),
  ?assert( {error, full} =:= Attempt2 ),
  ?assert( {ok, 1} =:= ?TESTED_MODULE:read(Pid) ).

producer_consumer_test() ->
  Pid = ?TESTED_MODULE:create( 3 ),
  erlang:spawn( fun() ->
                    [?TESTED_MODULE:write(Pid, X) || X <- [1,2,3]]
                end ),
  My_pid = erlang:self(),
  Ref = erlang:make_ref(),
  erlang:spawn( fun() ->
                    My_pid ! {Ref, [?TESTED_MODULE:read(Pid) || _X <- [1,2,3]]}
                end ),
  Reads = receive
            {Ref, R} -> R
          end,
  ?assert( Reads =:= [{ok, 1}, {ok, 2}, {ok, 3}] ).

Version data entries

194 entries across 194 versions & 1 rubygems

Version Path
trackler-2.2.1.62 tracks/erlang/exercises/circular-buffer/test/circular_buffer_tests.erl
trackler-2.2.1.61 tracks/erlang/exercises/circular-buffer/test/circular_buffer_tests.erl
trackler-2.2.1.60 tracks/erlang/exercises/circular-buffer/test/circular_buffer_tests.erl
trackler-2.2.1.59 tracks/erlang/exercises/circular-buffer/test/circular_buffer_tests.erl
trackler-2.2.1.58 tracks/erlang/exercises/circular-buffer/test/circular_buffer_tests.erl
trackler-2.2.1.57 tracks/erlang/exercises/circular-buffer/test/circular_buffer_tests.erl
trackler-2.2.1.56 tracks/erlang/exercises/circular-buffer/test/circular_buffer_tests.erl
trackler-2.2.1.55 tracks/erlang/exercises/circular-buffer/test/circular_buffer_tests.erl
trackler-2.2.1.54 tracks/erlang/exercises/circular-buffer/test/circular_buffer_tests.erl
trackler-2.2.1.53 tracks/erlang/exercises/circular-buffer/test/circular_buffer_tests.erl
trackler-2.2.1.52 tracks/erlang/exercises/circular-buffer/test/circular_buffer_tests.erl
trackler-2.2.1.51 tracks/erlang/exercises/circular-buffer/test/circular_buffer_tests.erl
trackler-2.2.1.50 tracks/erlang/exercises/circular-buffer/test/circular_buffer_tests.erl
trackler-2.2.1.49 tracks/erlang/exercises/circular-buffer/test/circular_buffer_tests.erl
trackler-2.2.1.48 tracks/erlang/exercises/circular-buffer/test/circular_buffer_tests.erl
trackler-2.2.1.47 tracks/erlang/exercises/circular-buffer/test/circular_buffer_tests.erl
trackler-2.2.1.46 tracks/erlang/exercises/circular-buffer/test/circular_buffer_tests.erl
trackler-2.2.1.45 tracks/erlang/exercises/circular-buffer/test/circular_buffer_tests.erl
trackler-2.2.1.44 tracks/erlang/exercises/circular-buffer/test/circular_buffer_tests.erl
trackler-2.2.1.43 tracks/erlang/exercises/circular-buffer/test/circular_buffer_tests.erl