From 71c99d63a313d497c3881ab06752f05e3af33350 Mon Sep 17 00:00:00 2001 From: Eduardo Julian Date: Thu, 5 Mar 2020 21:32:13 -0400 Subject: Test for equivalence + adjustments to Lua-generation code. --- stdlib/source/test/lux/abstract.lux | 5 ++-- stdlib/source/test/lux/abstract/equivalence.lux | 34 ++++++++++++++++++++++++- 2 files changed, 36 insertions(+), 3 deletions(-) (limited to 'stdlib/source/test') diff --git a/stdlib/source/test/lux/abstract.lux b/stdlib/source/test/lux/abstract.lux index b35b38137..b18d1c61b 100644 --- a/stdlib/source/test/lux/abstract.lux +++ b/stdlib/source/test/lux/abstract.lux @@ -4,6 +4,7 @@ ["." / #_ ["#." codec] ["#." enum] + ["#." equivalence] ["#." interval]]) (def: #export test @@ -11,5 +12,5 @@ ($_ _.and /codec.test /enum.test - /interval.test - )) + /equivalence.test + /interval.test)) diff --git a/stdlib/source/test/lux/abstract/equivalence.lux b/stdlib/source/test/lux/abstract/equivalence.lux index ac0084e82..7ae9b37af 100644 --- a/stdlib/source/test/lux/abstract/equivalence.lux +++ b/stdlib/source/test/lux/abstract/equivalence.lux @@ -3,13 +3,45 @@ ["_" test (#+ Test)] [abstract/monad (#+ do)] [data + ["." bit ("#@." equivalence)] [text - ["%" format (#+ format)]]] + ["%" format (#+ format)]] + [number + ["n" nat] + ["i" int]]] [math ["r" random (#+ Random)]]] {1 ["." / (#+ Equivalence)]}) +(def: #export test + Test + (do r.monad + [leftN r.nat + rightN r.nat + leftI r.int + rightI r.int] + (<| (_.context (%.name (name-of /._))) + ($_ _.and + (_.test (%.name (name-of /.sum)) + (let [equivalence (/.sum n.equivalence i.equivalence)] + (and (bit@= (:: n.equivalence = leftN leftN) + (:: equivalence = (#.Left leftN) (#.Left leftN))) + (bit@= (:: n.equivalence = leftN rightN) + (:: equivalence = (#.Left leftN) (#.Left rightN))) + (bit@= (:: i.equivalence = leftI leftI) + (:: equivalence = (#.Right leftI) (#.Right leftI))) + (bit@= (:: i.equivalence = leftI rightI) + (:: equivalence = (#.Right leftI) (#.Right rightI)))))) + (_.test (%.name (name-of /.product)) + (let [equivalence (/.product n.equivalence i.equivalence)] + (and (bit@= (and (:: n.equivalence = leftN leftN) + (:: i.equivalence = leftI leftI)) + (:: equivalence = [leftN leftI] [leftN leftI])) + (bit@= (and (:: n.equivalence = leftN rightN) + (:: i.equivalence = leftI rightI)) + (:: equivalence = [leftN leftI] [rightN rightI]))))))))) + (def: #export (spec (^open "_@.") generator) (All [a] (-> (Equivalence a) (Random a) Test)) (do r.monad -- cgit v1.2.3