Sha256: af82d952667383489bb05db511729f635d8414bf675379a514088fe338b3e121

Contents?: true

Size: 1.81 KB

Versions: 84

Compression:

Stored size: 1.81 KB

Contents

-module( circular_buffer_tests ).
-include_lib( "eunit/include/eunit.hrl" ).

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

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

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

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

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

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

Version data entries

84 entries across 84 versions & 1 rubygems

Version Path
trackler-2.0.6.28 tracks/erlang/exercises/circular-buffer/circular_buffer_tests.erl
trackler-2.0.6.27 tracks/erlang/exercises/circular-buffer/circular_buffer_tests.erl
trackler-2.0.6.26 tracks/erlang/exercises/circular-buffer/circular_buffer_tests.erl
trackler-2.0.6.25 tracks/erlang/exercises/circular-buffer/circular_buffer_tests.erl
trackler-2.0.6.24 tracks/erlang/exercises/circular-buffer/circular_buffer_tests.erl
trackler-2.0.6.23 tracks/erlang/exercises/circular-buffer/circular_buffer_tests.erl
trackler-2.0.6.22 tracks/erlang/exercises/circular-buffer/circular_buffer_tests.erl
trackler-2.0.6.21 tracks/erlang/exercises/circular-buffer/circular_buffer_tests.erl
trackler-2.0.6.20 tracks/erlang/exercises/circular-buffer/circular_buffer_tests.erl
trackler-2.0.6.19 tracks/erlang/exercises/circular-buffer/circular_buffer_tests.erl
trackler-2.0.6.18 tracks/erlang/exercises/circular-buffer/circular_buffer_tests.erl
trackler-2.0.6.17 tracks/erlang/exercises/circular-buffer/circular_buffer_tests.erl
trackler-2.0.6.16 tracks/erlang/exercises/circular-buffer/circular_buffer_tests.erl
trackler-2.0.6.15 tracks/erlang/exercises/circular-buffer/circular_buffer_tests.erl
trackler-2.0.6.14 tracks/erlang/exercises/circular-buffer/circular_buffer_tests.erl
trackler-2.0.6.13 tracks/erlang/exercises/circular-buffer/circular_buffer_tests.erl
trackler-2.0.6.12 tracks/erlang/exercises/circular-buffer/circular_buffer_tests.erl
trackler-2.0.6.11 tracks/erlang/exercises/circular-buffer/circular_buffer_tests.erl
trackler-2.0.6.10 tracks/erlang/exercises/circular-buffer/circular_buffer_tests.erl
trackler-2.0.6.9 tracks/erlang/exercises/circular-buffer/circular_buffer_tests.erl