Skip to content

Instantly share code, notes, and snippets.

View renatorozas's full-sized avatar

Renato Rozas renatorozas

View GitHub Profile
@renatorozas
renatorozas / kv_db_tests.erl
Created March 15, 2016 03:32
Getting started with EUnit (Part 2)
-module(kv_db_tests).
-include_lib("eunit/include/eunit.hrl").
all_test_() ->
[?_assertEqual([], kv_db:new()),
put_one_test(),
put_same_key_test(),
put_new_key_test(),
get_non_existent_key_test(),
@renatorozas
renatorozas / kv_db_tests.erl
Created March 15, 2016 02:50
Getting started with EUnit (Part 2)
-module(kv_db_tests).
-include_lib("eunit/include/eunit.hrl").
new_test_() ->
?_assertEqual([], kv_db:new()).
new_test() ->
?assertEqual([], kv_db:new()).
@renatorozas
renatorozas / kv_db_tests.erl
Created March 15, 2016 02:41
Getting started with EUnit (Part 2)
-module(kv_db_tests).
-include_lib("eunit/include/eunit.hrl").
new_test_() ->
?_test(?assertEqual([], kv_db:new())).
new_test() ->
?assertEqual([], kv_db:new()).
@renatorozas
renatorozas / kv_db_tests.erl
Created March 15, 2016 02:27
Getting started with EUnit (Part 2)
-module(kv_db_tests).
-include_lib("eunit/include/eunit.hrl").
new_test_() ->
fun () -> ?assertEqual([], kv_db:new()) end.
new_test() ->
?assertEqual([], kv_db:new()).
@renatorozas
renatorozas / kv_db_server.erl
Created March 10, 2016 15:14
Getting started with gen_server
-module(kv_db_server).
-behaviour(gen_server).
-export([init/1, handle_call/3, handle_cast/2,
handle_info/2, terminate/2, code_change/3]).
-export([start/0, put/2, get/1, delete/1, ls/0]).
% public functions
@renatorozas
renatorozas / kv_db_server.erl
Last active March 10, 2016 14:55
Getting started with gen_server
-module(kv_db_server).
-behaviour(gen_server).
-export([init/1, handle_call/3, handle_cast/2,
handle_info/2, terminate/2, code_change/3]).
-export([start/0]).
% public functions
@renatorozas
renatorozas / kv_db_server.erl
Last active March 10, 2016 14:42
Getting started with gen_server
% Defines the module.
-module(kv_db_server).
% Makes the module implement the gen_server behaviour.
-behaviour(gen_server).
% Exports the required gen_server callbacks.
-export([init/1, handle_call/3, handle_cast/2, handle_info/2,
terminate/2, code_change/3]).
@renatorozas
renatorozas / kv_db.erl
Last active March 15, 2016 01:44
Getting started with EUnit (Part 1)
-module(kv_db).
-type db() :: [].
-type results() :: nonempty_list({Key::atom(), Value::term()}).
-type err() :: {'error', string()}.
-export_type([db/0, results/0, err/0]).
-export([new/0, put/3, get/2, delete/2]).
-spec new() -> db().
@renatorozas
renatorozas / kv_db_tests.erl
Last active March 9, 2016 07:53
Getting started with EUnit (Part 1)
-module(kv_db_tests).
-include_lib("eunit/include/eunit.hrl").
new_test() ->
?assertEqual([], kv_db:new()).
put_test() ->
Db0 = kv_db:new(),
Db1 = kv_db:put(color, "red", Db0),
@renatorozas
renatorozas / kv_db_tests.erl
Last active March 9, 2016 07:53
Getting started with EUnit (Part 1)
-module(kv_db_tests).
-include_lib("eunit/include/eunit.hrl").
new_test() ->
?assertEqual([], kv_db:new()).