numeric.spec updates
This commit is contained in:
parent
b3e0cf7b22
commit
4a69b632b6
@ -24,27 +24,119 @@
|
|||||||
int2 gen/small-integer]
|
int2 gen/small-integer]
|
||||||
(check-integer-gt int1 int2)))
|
(check-integer-gt int1 int2)))
|
||||||
|
|
||||||
;(defn check-float-gt
|
(defn check-float-gt
|
||||||
; [value1 value2]
|
[value1 value2]
|
||||||
; (let [start-state (-> state/empty-state
|
(if (or (< (m/abs value1) 0.0001) (< (m/abs value2) 0.0001))
|
||||||
; (state/push-to-stack :float value1)
|
true
|
||||||
; (state/push-to-stack :float value2))
|
(let [start-state (-> state/empty-state
|
||||||
; end-state ((:float_gt @instructions/instruction-table) start-state)
|
(state/push-to-stack :float value1)
|
||||||
; expected-result (> value1 value2)]
|
(state/push-to-stack :float value2))
|
||||||
; (println "Value 1:" value1)
|
end-state ((:float_gt @instructions/instruction-table) start-state)
|
||||||
; (println "Value 2:" value2)
|
expected-result (> value1 value2)]
|
||||||
; (println "Expected Result: " expected-result)
|
(= expected-result
|
||||||
; (println "Actual Result: "(state/peek-stack end-state :boolean))
|
(state/peek-stack end-state :boolean)))))
|
||||||
; (println "")
|
|
||||||
; (= expected-result
|
(defspec float-gt-spec 100
|
||||||
; (state/peek-stack end-state :boolean))))
|
(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
|
(defn check-integer-lte
|
||||||
; (prop/for-all [float1 (gen/double* {:infinite? false, :NaN? false, :min -1000000, :max 1000000})
|
[value1 value2]
|
||||||
; float2 (gen/double* {:infinite? false, :NaN? false, :min -1000000, :max 1000000})]
|
(let [start-state (-> state/empty-state
|
||||||
; (if (and (> (m/abs float1) 0.00001) (> (m/abs float2) 0.00001))
|
(state/push-to-stack :integer value1)
|
||||||
; (check-float-gt float1 float2))))
|
(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
|
(defn check-integer-add
|
||||||
[value1 value2]
|
[value1 value2]
|
||||||
@ -108,13 +200,15 @@
|
|||||||
|
|
||||||
(defn check-integer-mult
|
(defn check-integer-mult
|
||||||
[value1 value2]
|
[value1 value2]
|
||||||
|
(if (or (< (m/abs value1) 0.00001) (< (m/abs value2) 0.00001))
|
||||||
|
true
|
||||||
(let [start-state (-> state/empty-state
|
(let [start-state (-> state/empty-state
|
||||||
(state/push-to-stack :integer value1)
|
(state/push-to-stack :integer value1)
|
||||||
(state/push-to-stack :integer value2))
|
(state/push-to-stack :integer value2))
|
||||||
end-state ((:integer_mult @instructions/instruction-table) start-state)
|
end-state ((:integer_mult @instructions/instruction-table) start-state)
|
||||||
expected-result (* value1 value2)]
|
expected-result (* value1 value2)]
|
||||||
(= expected-result
|
(= expected-result
|
||||||
(state/peek-stack end-state :integer))))
|
(state/peek-stack end-state :integer)))))
|
||||||
|
|
||||||
(defspec integer-mult-spec 100
|
(defspec integer-mult-spec 100
|
||||||
(prop/for-all [int1 gen/small-integer
|
(prop/for-all [int1 gen/small-integer
|
||||||
@ -315,17 +409,132 @@
|
|||||||
; end-state ((:float_from_char @instructions/instruction-table) start-state)
|
; end-state ((:float_from_char @instructions/instruction-table) start-state)
|
||||||
; expected-result (float (c/get-ascii value1))]
|
; expected-result (float (c/get-ascii value1))]
|
||||||
; (= expected-result
|
; (= 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
|
;(defspec float-from-char-spec 100
|
||||||
; (prop/for-all [char1 gen/char]
|
; (prop/for-all [char1 gen/char]
|
||||||
; (check-float-from-char char1)))
|
; (check-float-from-char char1)))
|
||||||
|
|
||||||
|
|
||||||
;
|
;;;FROM STRING NEEDED
|
||||||
; (println "Expected Result: " expected-result)
|
|
||||||
; (println "Actual Result: "(state/peek-stack end-state :float))
|
(defn check-integer-inc
|
||||||
; (println "Value 1:" value1)
|
[value1]
|
||||||
; (println "Value 2:" value2)
|
(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)))
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user