Permalink
Browse files

initial commit

  • Loading branch information...
0 parents commit 70719f4a5ec72758c56b29915305a72df9ff085a @krestenkrab committed Apr 28, 2010
Showing with 971 additions and 0 deletions.
  1. +1 −0 .gitignore
  2. +14 −0 _build.cfg
  3. +4 −0 config/sys.config
  4. +4 −0 doc/overview.edoc
  5. +15 −0 ebin/triq.app
  6. +41 −0 include/triq.hrl
  7. +26 −0 include/triq_domain.hrl
  8. +116 −0 src/erjang_test.erl
  9. +45 −0 src/sample.erl
  10. +192 −0 src/triq.erl
  11. +60 −0 src/triq_app.erl
  12. +182 −0 src/triq_domain.erl
  13. +201 −0 src/triq_simplify.erl
  14. +70 −0 src/triq_sup.erl
@@ -0,0 +1 @@
+_build
@@ -0,0 +1,14 @@
+project : {
+ name : triq
+ vsn : "0.1.0.0"
+},
+
+build_dir : _build,
+
+ignore_dirs : ["_",
+ "."],
+
+ignore_apps : [],
+
+
+
@@ -0,0 +1,4 @@
+%%% -*- mode:erlang -*-
+%%% Warning - this config file *must* end with <dot><whitespace>
+
+[ {triq, []} ].
@@ -0,0 +1,4 @@
+@author Kresten Krab Thorup <krab@trifork.com>
+@copyright 2010 Trifork A/S
+@version {@vsn}
+
@@ -0,0 +1,15 @@
+%% This is the application resource file (.app file) for the triq,
+%% application.
+{application, triq,
+ [{description, "Trifork QuickCheck 0.1.0"},
+ {vsn, "0.1.0"},
+ {modules, [triq_app,
+ triq_sup,
+ triq,
+ triq_domain,
+ triq_simplify]},
+ {registered,[triq_sup]},
+ {applications, [kernel, stdlib]},
+ {mod, {triq_app,[]}},
+ {start_phases, []}]}.
+
@@ -0,0 +1,41 @@
+%%
+%% This file is part of Triq - Trifork QuickCheck
+%%
+%% Copyright (c) 2010 by Trifork
+%%
+%% Licensed under the Apache License, Version 2.0 (the "License");
+%% you may not use this file except in compliance with the License.
+%% You may obtain a copy of the License at
+%%
+%% http://www.apache.org/licenses/LICENSE-2.0
+%%
+%% Unless required by applicable law or agreed to in writing, software
+%% distributed under the License is distributed on an "AS IS" BASIS,
+%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+%% See the License for the specific language governing permissions and
+%% limitations under the License.
+%%
+
+-define(DELAY(X),fun()->X end).
+-define(FORCE(X), (X)()).
+
+%% properties
+-define(FORALL(X,Gen,Property),
+ {'prop:forall', Gen, ??X, fun(X)-> begin Property end end, ??Property}).
+-define(IMPLIES(Pre, Property),
+ {'prop:implies', Pre, ??Pre, fun() -> Property end, ??Property}).
+
+%% value domains
+-define(LET(X,Gen1,Gen2),
+ triq_domain:glet(Gen1, fun(X)->Gen2 end}).
+-define(SIZED(Size,Gen),
+ triq_domain:sized(Size,Gen)).
+
+
+-import(triq_domain, [list/1, tuple/1, int/0, real/0, elements/1, any/0, atom/0]).
+
+
+
+
+
+
@@ -0,0 +1,26 @@
+%%
+%% This file is part of Triq - Trifork QuickCheck
+%%
+%% Copyright (c) 2010 by Trifork
+%%
+%% Licensed under the Apache License, Version 2.0 (the "License");
+%% you may not use this file except in compliance with the License.
+%% You may obtain a copy of the License at
+%%
+%% http://www.apache.org/licenses/LICENSE-2.0
+%%
+%% Unless required by applicable law or agreed to in writing, software
+%% distributed under the License is distributed on an "AS IS" BASIS,
+%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+%% See the License for the specific language governing permissions and
+%% limitations under the License.
+%%
+
+-define(DOM,'@domain').
+
+-record('@domain',
+ {kind,
+ generate=fun triq_domain:generate_internal/2,
+ simplify=fun triq_simplify:simplify_internal/2
+ }).
+
@@ -0,0 +1,116 @@
+%%
+%% This file is part of Triq - Trifork QuickCheck
+%%
+%% Copyright (c) 2010 by Trifork
+%%
+%% Licensed under the Apache License, Version 2.0 (the "License");
+%% you may not use this file except in compliance with the License.
+%% You may obtain a copy of the License at
+%%
+%% http://www.apache.org/licenses/LICENSE-2.0
+%%
+%% Unless required by applicable law or agreed to in writing, software
+%% distributed under the License is distributed on an "AS IS" BASIS,
+%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+%% See the License for the specific language governing permissions and
+%% limitations under the License.
+%%
+
+%%
+%% Remote equivalence tests for erjang/erlang
+%% name of remote server is given with -other NAME
+%% on command line (assumed to be localhost).
+%%
+
+-module(erjang_test).
+
+-include("triq.hrl").
+
+-export([prop_binop/0, prop_echo/0, main/0, echo/1, echo2/1]).
+
+
+%% ===========================================
+%%
+%% ===========================================
+host([$@|Rest]) ->
+ Rest;
+host([_|T]) ->
+ host(T).
+host() ->
+ host(atom_to_list(node())).
+
+server() ->
+ {ok,[[Other]]} = init:get_argument(other),
+ list_to_atom(Other++[$@|host()]).
+
+call(Node,Mod,Fun,Args) ->
+ case rpc:call(Node, Mod,Fun,Args) of
+ {badrpc,{'EXIT',{Reason,[FirstTrace|_]}}} ->
+ {badrpc, {'EXIT',{Reason,[FirstTrace]}}};
+ Value -> Value
+ end.
+
+%% ===========================================
+%% Run Mod:Fun(Args) on beam
+%% ===========================================
+other(Mod,Fun,Args) when is_atom(Mod), is_atom(Fun), is_list(Args) ->
+ call(server(), Mod,Fun,Args).
+
+other(Fun,Args) when is_list(Args) ->
+ call(server(), erlang,Fun,Args).
+
+echo(Value) ->
+ Value.
+
+echo2(Value) ->
+ erlang:display(Value),
+ [N|_] = erlang:atom_to_list(Value),
+ N.
+
+
+%% ===========================================
+%% Run erlang:Fun(Args) here
+%% ===========================================
+here(Mod,Fun,Args) ->
+ call(node(),Mod,Fun,Args).
+here(Fun,Args) ->
+ call(node(),erlang,Fun,Args).
+
+
+
+%% ===========================================
+%% Property test for binary operators
+%% ===========================================
+prop_binop() ->
+ ?FORALL({A,B,OP},
+ {any(),any(),
+ elements(['>', '<',
+ '==', '=:=', '/=',
+ '=<', '>=',
+ '++',
+ '+', '-', '/', '*', 'div',
+ 'bsl', 'bsr',
+ 'or'
+ ])},
+ begin
+ Here = here(OP,[A,B]),
+ There = other(OP,[A,B]),
+% io:format("here=~p~nthere=~p~n~n", [Here,There]),
+ Here == There
+ end).
+
+prop_echo() ->
+ ?FORALL(X, any(),
+ begin
+ Here = X,
+ There = other(?MODULE, echo, [X]),
+% io:format("here=~p, there=~p~n", [Here,There]),
+ Here==There
+ end).
+
+%%
+%% run the test
+%%
+main() ->
+ triq:check(prop_echo()).
+
@@ -0,0 +1,45 @@
+-module(sample).
+
+-include("triq.hrl").
+
+-export([prop_append/0, prop_echo/0, prop_delete_2/0, main/0]).
+
+prop_append() ->
+ ?FORALL({Xs,Ys},{list(int()),list(int())},
+ lists:reverse(Xs++Ys)
+ ==
+ lists:reverse(Ys) ++ lists:reverse(Xs)).
+
+
+prop_delete_2() ->
+ ?FORALL(L,list(int()),
+ ?IMPLIES(L /= [],
+ ?FORALL(I,elements(L),
+ not lists:member(I,lists:delete(I,L))))).
+
+
+inverse('<') -> '>=';
+inverse('>') -> '=<';
+inverse('==') -> '/=';
+inverse('=:=') -> '=/=';
+inverse('=/=') -> '=:=';
+inverse('/=') -> '=='.
+
+
+prop_binop() ->
+ ?FORALL({A,B,OP}, {any(),any(),elements(['>','<'])},
+ erlang:OP(A,B)
+ ==
+ begin
+ ROP = inverse(OP),
+ not ( erlang:ROP(A,B) )
+ end
+ ).
+
+prop_echo() ->
+ ?FORALL(X, any(),
+ X == X).
+
+main() ->
+ triq:check(?MODULE)
+.
Oops, something went wrong.

0 comments on commit 70719f4

Please sign in to comment.