-
Notifications
You must be signed in to change notification settings - Fork 0
/
mybase64_tests.erl
76 lines (43 loc) · 3.19 KB
/
mybase64_tests.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
-module(mybase64_tests).
-include_lib("eunit/include/eunit.hrl").
-import(mybase64, [encode_base64/1, decode_base64/1]).
encode_one_byte_zeros_test() ->
?assertEqual(<<"AA==">>, encode_base64(<<0:8>>)).
decode_one_byte_zeros_test() ->
?assertEqual(<<0:8>>, decode_base64(<<"AA==">>)).
encode_two_bytes_zeros_test() ->
?assertEqual(<<"AAA=">>, encode_base64(<<0:(2*8)>>)).
decode_two_bytes_zeros_test() ->
?assertEqual(<<0:(2*8)>>, decode_base64(<<"AAA=">>)).
encode_three_bytes_zeros_test() ->
?assertEqual(<<"AAAA">>, encode_base64(<<0:(3*8)>>)).
decode_three_bytes_zeros_test() ->
?assertEqual(<<0:(3*8)>>, decode_base64(<<"AAAA">>)).
encode_empty_string_test() ->
?assertEqual(<<"">>, encode_base64(<<"">>)).
decode_empty_string_test() ->
?assertEqual(<<"">>, decode_base64(<<"">>)).
encode_nonempty_string1_test() ->
?assertEqual(<<"cGxlYXN1cmUu">>, encode_base64(<<"pleasure.">>)).
decode_nonempty_string1_test() ->
?assertEqual(<<"pleasure.">>, decode_base64(<<"cGxlYXN1cmUu">>)).
encode_nonempty_string2_test() ->
?assertEqual(<<"bGVhc3VyZS4=">>, encode_base64(<<"leasure.">>)).
decode_nonempty_string2_test() ->
?assertEqual(<<"leasure.">>, decode_base64(<<"bGVhc3VyZS4=">>)).
encode_nonempty_string3_test() ->
?assertEqual(<<"ZWFzdXJlLg==">>, encode_base64(<<"easure.">>)).
decode_nonempty_string3_test() ->
?assertEqual(<<"easure.">>, decode_base64(<<"ZWFzdXJlLg==">>)).
encode_nonempty_string4_test() ->
?assertEqual(<<"YXN1cmUu">>, encode_base64(<<"asure.">>)).
decode_nonempty_string4_test() ->
?assertEqual(<<"asure.">>, decode_base64(<<"YXN1cmUu">>)).
encode_nonempty_string5_test() ->
?assertEqual(<<"c3VyZS4=">>, encode_base64(<<"sure.">>)).
decode_nonempty_string5_test() ->
?assertEqual(<<"sure.">>, decode_base64(<<"c3VyZS4=">>)).
encode_leviathan_test() ->
?assertEqual(<<"TWFuIGlzIGRpc3Rpbmd1aXNoZWQsIG5vdCBvbmx5IGJ5IGhpcyByZWFzb24sIGJ1dCBieSB0aGlzIHNpbmd1bGFyIHBhc3Npb24gZnJvbSBvdGhlciBhbmltYWxzLCB3aGljaCBpcyBhIGx1c3Qgb2YgdGhlIG1pbmQsIHRoYXQgYnkgYSBwZXJzZXZlcmFuY2Ugb2YgZGVsaWdodCBpbiB0aGUgY29udGludWVkIGFuZCBpbmRlZmF0aWdhYmxlIGdlbmVyYXRpb24gb2Yga25vd2xlZGdlLCBleGNlZWRzIHRoZSBzaG9ydCB2ZWhlbWVuY2Ugb2YgYW55IGNhcm5hbCBwbGVhc3VyZS4=">>, encode_base64(<<"Man is distinguished, not only by his reason, but by this singular passion from other animals, which is a lust of the mind, that by a perseverance of delight in the continued and indefatigable generation of knowledge, exceeds the short vehemence of any carnal pleasure.">>)).
decode_leviathan_test() ->
?assertEqual(<<"Man is distinguished, not only by his reason, but by this singular passion from other animals, which is a lust of the mind, that by a perseverance of delight in the continued and indefatigable generation of knowledge, exceeds the short vehemence of any carnal pleasure.">>, decode_base64(<<"TWFuIGlzIGRpc3Rpbmd1aXNoZWQsIG5vdCBvbmx5IGJ5IGhpcyByZWFzb24sIGJ1dCBieSB0aGlzIHNpbmd1bGFyIHBhc3Npb24gZnJvbSBvdGhlciBhbmltYWxzLCB3aGljaCBpcyBhIGx1c3Qgb2YgdGhlIG1pbmQsIHRoYXQgYnkgYSBwZXJzZXZlcmFuY2Ugb2YgZGVsaWdodCBpbiB0aGUgY29udGludWVkIGFuZCBpbmRlZmF0aWdhYmxlIGdlbmVyYXRpb24gb2Yga25vd2xlZGdlLCBleGNlZWRzIHRoZSBzaG9ydCB2ZWhlbWVuY2Ugb2YgYW55IGNhcm5hbCBwbGVhc3VyZS4=">>)).