numeric.spec updates

This commit is contained in:
Julia Schor 2022-01-29 12:42:17 -05:00
parent b3e0cf7b22
commit 4a69b632b6

View File

@ -24,27 +24,119 @@
int2 gen/small-integer]
(check-integer-gt int1 int2)))
;(defn check-float-gt
; [value1 value2]
; (let [start-state (-> state/empty-state
; (state/push-to-stack :float value1)
; (state/push-to-stack :float value2))
; end-state ((:float_gt @instructions/instruction-table) start-state)
; expected-result (> value1 value2)]
; (println "Value 1:" value1)
; (println "Value 2:" value2)
; (println "Expected Result: " expected-result)
; (println "Actual Result: "(state/peek-stack end-state :boolean))
; (println "")
; (= expected-result
; (state/peek-stack end-state :boolean))))
(defn check-float-gt
[value1 value2]
(if (or (< (m/abs value1) 0.0001) (< (m/abs value2) 0.0001))
true
(let [start-state (-> state/empty-state
(state/push-to-stack :float value1)
(state/push-to-stack :float value2))
end-state ((:float_gt @instructions/instruction-table) start-state)
expected-result (> value1 value2)]
(= expected-result
(state/peek-stack end-state :boolean)))))
(defspec float-gt-spec 100
(prop/for-all [float1 (gen/double* {:infinite? false, :NaN? false, :min -1000000, :max 1000000})
float2 (gen/double* {:infinite? false, :NaN? false, :min -1000000, :max 1000000})]
(check-float-gt float1 float2)))
(defn check-integer-gte
[value1 value2]
(let [start-state (-> state/empty-state
(state/push-to-stack :integer value1)
(state/push-to-stack :integer value2))
end-state ((:integer_gte @instructions/instruction-table) start-state)
expected-result (>= value1 value2)]
(= expected-result
(state/peek-stack end-state :boolean))))
(defspec integer-gte-spec 100
(prop/for-all [int1 gen/small-integer
int2 gen/small-integer]
(check-integer-gte int1 int2)))
(defn check-float-gte
[value1 value2]
(if (or (< (m/abs value1) 0.0001) (< (m/abs value2) 0.0001))
true
(let [start-state (-> state/empty-state
(state/push-to-stack :float value1)
(state/push-to-stack :float value2))
end-state ((:float_gte @instructions/instruction-table) start-state)
expected-result (>= value1 value2)]
(= expected-result
(state/peek-stack end-state :boolean)))))
(defspec float-gte-spec 100
(prop/for-all [float1 (gen/double* {:infinite? false, :NaN? false, :min -1000000, :max 1000000})
float2 (gen/double* {:infinite? false, :NaN? false, :min -1000000, :max 1000000})]
(check-float-gte float1 float2)))
(defn check-integer-lt
[value1 value2]
(let [start-state (-> state/empty-state
(state/push-to-stack :integer value1)
(state/push-to-stack :integer value2))
end-state ((:integer_lt @instructions/instruction-table) start-state)
expected-result (< value1 value2)]
(= expected-result
(state/peek-stack end-state :boolean))))
(defspec integer-lt-spec 100
(prop/for-all [int1 gen/small-integer
int2 gen/small-integer]
(check-integer-lt int1 int2)))
(defn check-float-lt
[value1 value2]
(if (or (< (m/abs value1) 0.0001) (< (m/abs value2) 0.0001))
true
(let [start-state (-> state/empty-state
(state/push-to-stack :float value1)
(state/push-to-stack :float value2))
end-state ((:float_lt @instructions/instruction-table) start-state)
expected-result (< value1 value2)]
(= expected-result
(state/peek-stack end-state :boolean)))))
(defspec float-lt-spec 100
(prop/for-all [float1 (gen/double* {:infinite? false, :NaN? false, :min -1000000, :max 1000000})
float2 (gen/double* {:infinite? false, :NaN? false, :min -1000000, :max 1000000})]
(check-float-lt float1 float2)))
;(defspec float-gt-spec 100
; (prop/for-all [float1 (gen/double* {:infinite? false, :NaN? false, :min -1000000, :max 1000000})
; float2 (gen/double* {:infinite? false, :NaN? false, :min -1000000, :max 1000000})]
; (if (and (> (m/abs float1) 0.00001) (> (m/abs float2) 0.00001))
; (check-float-gt float1 float2))))
(defn check-integer-lte
[value1 value2]
(let [start-state (-> state/empty-state
(state/push-to-stack :integer value1)
(state/push-to-stack :integer value2))
end-state ((:integer_lte @instructions/instruction-table) start-state)
expected-result (<= value1 value2)]
(= expected-result
(state/peek-stack end-state :boolean))))
(defspec integer-lte-spec 100
(prop/for-all [int1 gen/small-integer
int2 gen/small-integer]
(check-integer-lte int1 int2)))
(defn check-float-lte
[value1 value2]
(if (or (< (m/abs value1) 0.0001) (< (m/abs value2) 0.0001))
true
(let [start-state (-> state/empty-state
(state/push-to-stack :float value1)
(state/push-to-stack :float value2))
end-state ((:float_lte @instructions/instruction-table) start-state)
expected-result (<= value1 value2)]
(= expected-result
(state/peek-stack end-state :boolean)))))
(defspec float-lte-spec 100
(prop/for-all [float1 (gen/double* {:infinite? false, :NaN? false, :min -1000000, :max 1000000})
float2 (gen/double* {:infinite? false, :NaN? false, :min -1000000, :max 1000000})]
(check-float-lte float1 float2)))
(defn check-integer-add
[value1 value2]
@ -108,13 +200,15 @@
(defn check-integer-mult
[value1 value2]
(if (or (< (m/abs value1) 0.00001) (< (m/abs value2) 0.00001))
true
(let [start-state (-> state/empty-state
(state/push-to-stack :integer value1)
(state/push-to-stack :integer value2))
end-state ((:integer_mult @instructions/instruction-table) start-state)
expected-result (* value1 value2)]
(= expected-result
(state/peek-stack end-state :integer))))
(state/peek-stack end-state :integer)))))
(defspec integer-mult-spec 100
(prop/for-all [int1 gen/small-integer
@ -315,17 +409,132 @@
; end-state ((:float_from_char @instructions/instruction-table) start-state)
; expected-result (float (c/get-ascii value1))]
; (= expected-result
; (state/peek-stack end-state :float))))
; (state/peek-stack end-state :char))))
;(println (check-float-from-char (first "abc")))
;
;(defspec float-from-char-spec 100
; (prop/for-all [char1 gen/char]
; (check-float-from-char char1)))
;
; (println "Expected Result: " expected-result)
; (println "Actual Result: "(state/peek-stack end-state :float))
; (println "Value 1:" value1)
; (println "Value 2:" value2)
;
;
;;;FROM STRING NEEDED
(defn check-integer-inc
[value1]
(let [start-state (-> state/empty-state
(state/push-to-stack :integer value1))
end-state ((:integer_inc @instructions/instruction-table) start-state)
expected-result (+ value1 1)]
(= expected-result
(state/peek-stack end-state :integer))))
(defspec integer-inc-spec 100
(prop/for-all [int1 gen/small-integer]
(check-integer-inc int1)))
(defn check-float-inc
[value1]
(let [start-state (-> state/empty-state
(state/push-to-stack :float value1))
end-state ((:float_inc @instructions/instruction-table) start-state)
expected-result (+ value1 1.0)]
(m/approx= expected-result
(state/peek-stack end-state :float) 0.0001)))
(defspec float-inc-spec 100
(prop/for-all [float1 (gen/double* {:infinite? false, :NaN? false, :min -1000000, :max 999999})]
(check-float-inc float1)))
(defn check-integer-dec
[value1]
(let [start-state (-> state/empty-state
(state/push-to-stack :integer value1))
end-state ((:integer_dec @instructions/instruction-table) start-state)
expected-result (- value1 1)]
(= expected-result
(state/peek-stack end-state :integer))))
(defspec integer-dec-spec 100
(prop/for-all [int1 gen/small-integer]
(check-integer-dec int1)))
(defn check-float-dec
[value1]
(let [start-state (-> state/empty-state
(state/push-to-stack :float value1))
end-state ((:float_dec @instructions/instruction-table) start-state)
expected-result (- value1 1.0)]
(m/approx= expected-result
(state/peek-stack end-state :float) 0.0001)))
(defspec float-dec-spec 100
(prop/for-all [float1 (gen/double* {:infinite? false, :NaN? false, :min -999999, :max 1000000})]
(check-float-dec float1)))
(defn check-float-cos
[value1]
(let [start-state (-> state/empty-state
(state/push-to-stack :float value1))
end-state ((:float_cos @instructions/instruction-table) start-state)
expected-result (m/cos value1)]
(m/approx= expected-result
(state/peek-stack end-state :float) 0.001)))
(defspec float-cos-spec 100
(prop/for-all [float1 (gen/double* {:infinite? false, :NaN? false, :min -1000000, :max 1000000})]
(check-float-cos float1)))
(defn check-float-sin
[value1]
(let [start-state (-> state/empty-state
(state/push-to-stack :float value1))
end-state ((:float_sin @instructions/instruction-table) start-state)
expected-result (m/sin value1)]
(m/approx= expected-result
(state/peek-stack end-state :float) 0.001)))
(defspec float-sin-spec 100
(prop/for-all [float1 (gen/double* {:infinite? false, :NaN? false, :min -1000000, :max 1000000})]
(check-float-sin float1)))
(defn check-float-tan
[value1]
(let [start-state (-> state/empty-state
(state/push-to-stack :float value1))
end-state ((:float_tan @instructions/instruction-table) start-state)
expected-result (m/tan value1)]
(m/approx= expected-result
(state/peek-stack end-state :float) 0.001)))
(defspec float-tan-spec 100
(prop/for-all [float1 (gen/double* {:infinite? false, :NaN? false, :min -1000000, :max 1000000})]
(check-float-tan float1)))
(defn check-float-from-integer
[value1]
(let [start-state (-> state/empty-state
(state/push-to-stack :integer value1))
end-state ((:float_from_integer @instructions/instruction-table) start-state)
expected-result (float value1)]
(= expected-result
(state/peek-stack end-state :float))))
(defspec float-from-integer-spec 100
(prop/for-all [int1 gen/small-integer]
(check-float-from-integer int1)))
(defn check-integer-from-float
[value1]
(let [start-state (-> state/empty-state
(state/push-to-stack :float value1))
end-state ((:integer_from_float @instructions/instruction-table) start-state)
expected-result (int value1)]
(= expected-result
(state/peek-stack end-state :integer))))
(defspec integer-from-float-spec 100
(prop/for-all [float1 (gen/double* {:infinite? false, :NaN? false, :min -1000000, :max 1000000})]
(check-integer-from-float float1)))