-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathadapter_db1_test.erl
41 lines (41 loc) · 1.37 KB
/
adapter_db1_test.erl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
%% ---
%% Excerpted from "Programming Erlang, Second Edition",
%% published by The Pragmatic Bookshelf.
%% Copyrights apply to this code. It may not be used to create training material,
%% courses, books, articles, and the like. Contact us if you are in doubt.
%% We make no guarantees that this code is fit for any purpose.
%% Visit http://www.pragmaticprogrammer.com/titles/jaerlang2 for more book information.
%%---
-module(adapter_db1_test).
-export([test/0]).
-import(adapter_db1, [new/1]).
test() ->
%% test the dict module
M0 = new(dict),
M1 = M0:store(key1, val1),
M2 = M1:store(key2, val2),
{ok, val1} = M2:lookup(key1),
{ok, val2} = M2:lookup(key2),
error = M2:lookup(nokey),
%% test the lists module
N0 = new(lists),
N1 = N0:store(key1, val1),
N2 = N1:store(key2, val2),
{ok, val1} = N2:lookup(key1),
{ok, val2} = N2:lookup(key2),
error = N2:lookup(nokey),
%% test the persistent module
P0 = new(persistent),
P1 = P0:store(key1, val1),
P2 = P1:store(key2, val2),
{ok, val1} = P2:lookup(key1),
{ok, val2} = P2:lookup(key2),
error = P2:lookup(nokey),
%% test the memory and disk module
MD0 = new(memory_and_disk),
MD1 = MD0:store(key1, val1),
MD2 = MD1:store(key2, val2),
{ok, val1} = MD2:lookup(key1),
{ok, val2} = MD2:lookup(key2),
error = MD2:lookup(nokey),
ok.