(.module: [library [lux #* ["_" test (#+ Test)] [abstract [monad (#+ do)]] [macro ["." template]] [math ["." random (#+ Random)] [number ["n" nat] ["i" int] ["f" frac]]]]] [\\library ["." /]] ["." / #_ ["#." infix] ["#." modulus] ["#." modular] ["#." number] ["#." logic #_ ["#/." continuous] ["#/." fuzzy]]]) (def: margin_of_error +0.0000001) (def: (trigonometric_symmetry forward backward angle) (-> (-> Frac Frac) (-> Frac Frac) Frac Bit) (let [normal (|> angle forward backward)] (|> normal forward backward (f.approximately? ..margin_of_error normal)))) (def: .public test Test (<| (_.covering /._) ($_ _.and (do {! random.monad} [.let [~= (f.approximately? ..margin_of_error)] angle (|> random.safe_frac (\ ! each (f.* /.tau)))] ($_ _.and (_.cover [/.sin /.asin] (trigonometric_symmetry /.sin /.asin angle)) (_.cover [/.cos /.acos] (trigonometric_symmetry /.cos /.acos angle)) (_.cover [/.tan /.atan] (trigonometric_symmetry /.tan /.atan angle)) (_.cover [/.tau] (and (and (~= +0.0 (/.sin /.tau)) (~= +1.0 (/.cos /.tau))) (and (~= +0.0 (/.sin (f./ +2.0 /.tau))) (~= -1.0 (/.cos (f./ +2.0 /.tau)))) (and (~= +1.0 (/.sin (f./ +4.0 /.tau))) (~= +0.0 (/.cos (f./ +4.0 /.tau)))) (and (~= -1.0 (/.sin (f.* +3.0 (f./ +4.0 /.tau)))) (~= +0.0 (/.cos (f.* +3.0 (f./ +4.0 /.tau))))) (let [x2+y2 (f.+ (/.pow +2.0 (/.sin angle)) (/.pow +2.0 (/.cos angle)))] (~= +1.0 x2+y2)))) (_.cover [/.pi] (~= (f./ +2.0 /.tau) /.pi)) )) (do {! random.monad} [sample (|> random.safe_frac (\ ! each (f.* +1000.0)))] ($_ _.and (_.cover [/.ceil] (let [ceil'd (/.ceil sample)] (and (|> ceil'd f.int i.frac (f.= ceil'd)) (f.>= sample ceil'd) (f.<= +1.0 (f.- sample ceil'd))))) (_.cover [/.floor] (let [floor'd (/.floor sample)] (and (|> floor'd f.int i.frac (f.= floor'd)) (f.<= sample floor'd) (f.<= +1.0 (f.- floor'd sample))))) (_.cover [/.round] (let [round'd (/.round sample)] (and (|> round'd f.int i.frac (f.= round'd)) (f.<= +1.0 (f.abs (f.- sample round'd)))))) (_.cover [/.root/2] (let [sample (f.abs sample)] (|> sample /.root/2 (/.pow +2.0) (f.approximately? ..margin_of_error sample)))) (_.cover [/.root/3] (|> sample /.root/3 (/.pow +3.0) (f.approximately? ..margin_of_error sample))) )) (do {! random.monad} [.let [~= (f.approximately? ..margin_of_error)] sample (\ ! each (f.* +10.0) random.safe_frac) power (\ ! each (|>> (n.% 10) ++ n.frac) random.nat)] ($_ _.and (_.cover [/.exp /.log] (|> sample /.exp /.log (f.approximately? +0.000000000000001 sample))) (_.cover [/.e] (~= +1.0 (/.log /.e))) (_.cover [/.pow /.log_by] (let [sample (f.abs sample)] (|> sample (/.pow power) (/.log_by sample) (~= power)))) )) (do {! random.monad} [.let [~= (f.approximately? ..margin_of_error)] angle (\ ! each (f.* /.tau) random.safe_frac) sample (\ ! each f.abs random.safe_frac) big (\ ! each (f.* +1,000,000,000.00) random.safe_frac)] (template.let [(odd! ) [(_.cover [] (~= (f.opposite ( angle)) ( (f.opposite angle))))] (even! ) [(_.cover [] (~= ( angle) ( (f.opposite angle))))] (inverse! ) [(_.cover [ ] (~= ( ) ( (f./ +1.0))))]] ($_ _.and (odd! /.sinh) (even! /.cosh) (odd! /.tanh) (odd! /.coth) (even! /.sech) (odd! /.csch) (inverse! /.acosh /.asech sample) (inverse! /.asinh /.acsch sample) (inverse! /.atanh /.acoth big) ))) (do {! random.monad} [x (\ ! each (|>> (f.* +10.0) f.abs) random.safe_frac) y (\ ! each (|>> (f.* +10.0) f.abs) random.safe_frac)] (_.cover [/.hypotenuse] (let [h (/.hypotenuse x y)] (and (f.>= x h) (f.>= y h))))) (do {! random.monad} [.let [~= (f.approximately? ..margin_of_error) tau/4 (f./ +4.0 /.tau)] x (\ ! each (f.* tau/4) random.safe_frac) y (\ ! each (f.* tau/4) random.safe_frac)] (_.cover [/.atan/2] (let [expected (/.atan/2 x y) actual (if (f.> +0.0 x) (/.atan (f./ x y)) (if (f.< +0.0 y) (f.- /.pi (/.atan (f./ x y))) (f.+ /.pi (/.atan (f./ x y)))))] (and (~= expected actual) (~= tau/4 (/.atan/2 +0.0 (f.abs y))) (~= (f.opposite tau/4) (/.atan/2 +0.0 (f.opposite (f.abs y)))) (f.not_a_number? (/.atan/2 +0.0 +0.0)))))) (do {! random.monad} [of (\ ! each (|>> (n.% 10) ++) random.nat)] (_.cover [/.factorial] (and (n.= 1 (/.factorial 0)) (|> (/.factorial of) (n.% of) (n.= 0))))) /infix.test /modulus.test /modular.test /number.test /logic/continuous.test /logic/fuzzy.test )))