Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

binaries

  • Loading branch information...
commit 4c916e13dba57b641a2fcbdcbe052551c91f994f 1 parent fbd4b9e
@giorgiosironi authored
Showing with 37 additions and 0 deletions.
  1. +37 −0 src/binaries_15.erl
View
37 src/binaries_15.erl
@@ -0,0 +1,37 @@
+-module(binaries_15).
+-include_lib("eunit/include/eunit.hrl").
+
+binary_representation_test() ->
+ Bin = term_to_binary(a),
+ ?assertEqual(<<131, 100, 0, 1, 97>>, Bin).
+
+binary_conversions_test() ->
+ Bin = term_to_binary(a),
+ ?assertEqual(a, binary_to_term(Bin)).
+
+binary_complex_conversions_test() ->
+ Bin = term_to_binary({a, 42, {b, c}}),
+ ?assertEqual({a, 42, {b, c}}, binary_to_term(Bin)).
+
+bit_building_test() ->
+ G=6*16+6,
+ B=9*16+9,
+ Bin = <<0, G, B>>,
+ ?assertEqual([0, G, B], binary_to_list(Bin)).
+
+bit_pattern_matching_test() ->
+ G=6*16+6,
+ B=9*16+9,
+ Bin = <<0, G, B>>,
+ <<0, G, Blue>> = Bin,
+ ?assertEqual(B, Blue).
+
+bin_types_test() ->
+ ?assertEqual(<<"A">>, <<4:4, 1:4>>).
+
+bin_pattern_matching_with_types_test() ->
+ Bin = <<"Answer", 42, "ok">>,
+ <<"Answer", Int, Result/binary>> = Bin,
+ ?assertEqual(42, Int),
+ ?assertEqual(<<"ok">>, Result).
+
Please sign in to comment.
Something went wrong with that request. Please try again.