source: trunk/src/adlib_test.erl @ 80

Revision 80, 1.7 KB checked in by dom, 3 years ago (diff)

Fixed more bugs in directory_watcher.

Line 
1%%% Copyright (C) 2009 Dominic Williams
2%%% All rights reserved.
3%%% See file COPYING.
4
5-module(adlib_test).
6-test (exports).
7-export ([dict_compare_empty/0]).
8-export ([dict_compare_empty_with_non_empty/0]).
9-export ([dict_compare/0]).
10
11dict_compare_empty () ->
12    Empty = dict: new (),
13    Result = adlib: compare_dict (Empty, Empty),
14    Keys = [new, lost, changed, same],
15    [Empty, Empty, Empty, Empty] = [dict: fetch (Key, Result) || Key <- Keys],
16    ok.
17
18dict_compare_empty_with_non_empty () ->
19    Empty = dict: new (),
20    Non_empty = dict: store (mykey, myvalue, Empty),
21    Keys = [new, lost, changed, same],
22    Result1 = adlib: compare_dict (Non_empty, Empty),
23    [Non_empty, Empty, Empty, Empty] = [dict: fetch (Key, Result1) || Key <- Keys],
24    Result2 = adlib: compare_dict (Empty, Non_empty),
25    [Empty, Non_empty, Empty, Empty] = [dict: fetch (Key, Result2) || Key <- Keys],
26    ok.
27   
28dict_compare () ->
29    Original_list = [{a,a},{b,b},{c,c},{d,d},{e,e},{f,f}],
30    Modified_list = [{a,b},{b,b},{d,d},{e,f},{g,g},{h,h}],
31    Original = dict: from_list (Original_list),
32    Modified = dict: from_list (Modified_list),
33    Result = adlib: compare_dict (Modified, Original),
34    Keys = [new, lost, changed, same],
35    [New, Lost, Changed, Same] = [dict: fetch (Key, Result) || Key <- Keys],
36    Expected_new = dict: from_list ([{g,g},{h,h}]),
37    Expected_lost = dict: from_list ([{c,c},{f,f}]),
38    Expected_changed = dict: from_list ([{a,{b,a}},{e,{f,e}}]),
39    Expected_same = dict: from_list ([{b,b},{d,d}]),
40    {new, Expected_new} = {new, New},
41    {lost, Expected_lost} = {lost, Lost},
42    {changed, Expected_changed} = {changed, Changed},
43    {same, Expected_same} = {same, Same}.
44   
Note: See TracBrowser for help on using the repository browser.