Permalink
Browse files

Initial checkin of lens test code.

  • Loading branch information...
1 parent 0a6b58d commit 21209ce04fd3bc97290107d71dcd56c9bd4c29c0 @jlouis committed Jul 7, 2012
Showing with 42 additions and 6 deletions.
  1. +3 −0 .gitignore
  2. +2 −0 Makefile
  3. +1 −3 rebar.config
  4. +2 −0 src/Makefile
  5. +34 −3 src/lens.erl
View
@@ -0,0 +1,3 @@
+*.beam
+/ebin/erlens.app
+/.eqc-info
View
@@ -0,0 +1,2 @@
+all:
+ rebar compile
View
@@ -4,11 +4,9 @@
warn_export_all,
warn_export_vars,
warn_obsolete_guard,
- warn_unused_import,
warn_bif_clash,
%% warn_missing_spec,
- warn_untyped_record,
- {parse_transform, lager_transform}]}.
+ warn_untyped_record]}.
{require_otp_vsn, "R15|R16"}.
View
@@ -0,0 +1,2 @@
+all:
+ $(MAKE) -C .. all
View
@@ -1,12 +1,43 @@
-module(lens).
+-include_lib("eqc/include/eqc.hrl").
+
-compile(export_all).
--record(r, {a, b}).
+-record(r, {a :: integer(),
+ b :: integer() }).
+
+gen_r() ->
+ ?LET({A, B}, {int(), int()},
+ #r { a = A, b = B}).
-lens() ->
+lens_a_access() ->
{fun(#r { a = A}) -> A end,
- fun(R, X) -> R#r { a = X } end}.
+ fun(X, R) -> R#r { a = X } end}.
+
+lens_b_access() ->
+ {fun(#r { b = A }) -> A end,
+ fun(X, R) -> R#r { b = X } end}.
+
+lens_prop_getput(Gen, Lens) ->
+ {Get, Put} = Lens,
+ ?FORALL(X, Gen,
+ X == Put(Get(X), X)).
+
+lens_prop_putget(Gen, Val, Lens) ->
+ {Get, Put} = Lens,
+ ?FORALL({X, A}, {Gen, Val},
+ A == Get(Put(A, X))).
+
+prop_t1() ->
+ lens_prop_getput(gen_r(), lens_a_access()).
+
+prop_t2() ->
+ lens_prop_getput(gen_r(), lens_b_access()).
+prop_t3() ->
+ lens_prop_putget(gen_r(), int(), lens_a_access()).
+prop_t4() ->
+ lens_prop_putget(gen_r(), int(), lens_b_access()).

0 comments on commit 21209ce

Please sign in to comment.