mirror of
https://github.com/carp-lang/Carp.git
synced 2024-11-12 12:49:13 +03:00
6f7aeaff73
* feat: 'delete' interface (deciding whether a type is managed or not) * refactor: Move implements function to Interface module * feat: Automatically implement 'delete' for types defined with `deftype` * fix: Don't implement `delete` for Pointer * refactor: Clarify `memberInfo` function * fix: Also check if function types are managed * fix: Implement 'delete' for String and StaticArray. * fix: Manage String and Pattern. Tests run! * feat: Add `managed?` primitive * docs: Note about primitiveIsManaged * test: Basic test cases for managed / nonmanaged external types * test: Make sure `managed?` primitive works * test: Inactivate sanitizer since we're creating leaks intentionally * feat: Removed 'isExternalType' function * refactor: Decide if struct member takes ref or not when printing ..based on blitable interface, and 'prn' implemntation * refactor: Use 'blit' everywhere * refactor: Implement `strTakesRefOrNot` in terms of `memberStrCallingConvention` * refactor: Use `remove` over `filter not`
101 lines
3.1 KiB
Plaintext
101 lines
3.1 KiB
Plaintext
(load "Test.carp")
|
|
(load "core/Statistics.carp") ;; specified path to avoid loading itself on case insensitive file systems
|
|
|
|
(use-all Double Test Statistics)
|
|
|
|
(defn all-eq [a b]
|
|
(if (/= (Array.length a) (Array.length b))
|
|
false
|
|
(let [res true]
|
|
(do
|
|
(for [i 0 (Array.length a)]
|
|
(if (not (Double.= @(Array.unsafe-nth a i) @(Array.unsafe-nth b i)))
|
|
(set! res false)
|
|
()))
|
|
res))))
|
|
|
|
(defn all-approx [a b]
|
|
(if (/= (Array.length a) (Array.length b))
|
|
false
|
|
(let [res true]
|
|
(do
|
|
(for [i 0 (Array.length a)]
|
|
(if (not (Double.approx @(Array.unsafe-nth a i) @(Array.unsafe-nth b i)))
|
|
(set! res false)
|
|
()))
|
|
res))))
|
|
|
|
(deftest test
|
|
(assert-equal test
|
|
2.0
|
|
(median &[1.0 2.0 3.0])
|
|
"median works as expected")
|
|
(assert-equal test
|
|
2.5
|
|
(mean &[1.0 2.0 4.5])
|
|
"mean works as expected")
|
|
(assert-equal test
|
|
2.0
|
|
(low-median &[1.0 2.0 4.0 5.0])
|
|
"low-median works as expected")
|
|
(assert-equal test
|
|
4.0
|
|
(high-median &[1.0 2.0 4.0 5.0])
|
|
"high-median works as expected")
|
|
(assert-equal test
|
|
3.0
|
|
(grouped-median &[1.0 2.0 4.0 5.0] 2)
|
|
"grouped-median works as expected I")
|
|
(assert-equal test
|
|
2.5
|
|
(grouped-median &[1.0 2.0 4.0 5.0] 3)
|
|
"grouped-median works as expected II")
|
|
(assert-equal test
|
|
1.0
|
|
(variance &[1.0 2.0 4.0 5.0])
|
|
"variance works as expected")
|
|
(assert-equal test
|
|
0.75
|
|
(pvariance &[1.0 2.0 4.0 5.0])
|
|
"pvariance works as expected")
|
|
(assert-equal test
|
|
2.0
|
|
(stdev &[1.0 1.0 9.0 9.0])
|
|
"stdev works as expected")
|
|
(assert-equal test
|
|
2.0
|
|
(pstdev &[1.0 9.0])
|
|
"pstdev works as expected")
|
|
(assert-op test
|
|
&[0.0 0.0 0.0 0.0 8.0]
|
|
&(winsorize &[0.0 0.0 0.0 0.0 10.0] 5.0)
|
|
"winsorizing works as expected"
|
|
all-approx)
|
|
(assert-op test
|
|
&[2.5 5.0 7.5]
|
|
&(quartiles &[0.0 2.5 5.0 7.5 10.0])
|
|
"quartiles work as expected"
|
|
all-eq)
|
|
(assert-equal test
|
|
5.0
|
|
(iqr &[0.0 2.5 5.0 7.5 10.0])
|
|
"iqr works as expected")
|
|
(assert-equal test
|
|
40.0
|
|
(stdev-pct &[1.0 1.0 9.0 9.0])
|
|
"stdev-pct works as expected")
|
|
(assert-op test
|
|
3.7065
|
|
(median-abs-dev &[5.0 10.0])
|
|
"median-abs-dev works as expected"
|
|
Double.approx)
|
|
(assert-op test
|
|
49.42
|
|
(median-abs-dev-pct &[5.0 10.0])
|
|
"median-abs-dev-pct works as expected"
|
|
Double.approx)
|
|
(assert-equal test
|
|
2.0
|
|
@(Summary.median &(summary &[1.0 2.0 3.0]))
|
|
"summary works as expected"))
|