|
| 1 | +{-# LANGUAGE GADTs #-} |
| 2 | + |
| 3 | +module Operations.Subset where |
| 4 | + |
| 5 | +import DataFrame.Internal.DataFrame |
| 6 | +import qualified DataFrame.Operations.Core as D |
| 7 | +import qualified DataFrame.Operations.Subset as D |
| 8 | +import System.Random |
| 9 | + |
| 10 | +prop_dropZero :: DataFrame -> Bool |
| 11 | +prop_dropZero df = D.drop 0 df == df |
| 12 | + |
| 13 | +prop_takeZero :: DataFrame -> Bool |
| 14 | +prop_takeZero df = fst (dataframeDimensions (D.take 0 df)) == 0 |
| 15 | + |
| 16 | +prop_takeAll :: DataFrame -> Bool |
| 17 | +prop_takeAll df = |
| 18 | + let n = fst (dataframeDimensions df) |
| 19 | + in D.take n df == df |
| 20 | + |
| 21 | +prop_dropAll :: DataFrame -> Bool |
| 22 | +prop_dropAll df = |
| 23 | + let n = fst (dataframeDimensions df) |
| 24 | + in fst (dataframeDimensions (D.drop n df)) == 0 |
| 25 | + |
| 26 | +prop_takeLastZero :: DataFrame -> Bool |
| 27 | +prop_takeLastZero df = fst (dataframeDimensions (D.takeLast 0 df)) == 0 |
| 28 | + |
| 29 | +prop_dropLastZero :: DataFrame -> Bool |
| 30 | +prop_dropLastZero df = D.dropLast 0 df == df |
| 31 | + |
| 32 | +prop_takeLastAll :: DataFrame -> Bool |
| 33 | +prop_takeLastAll df = |
| 34 | + let n = fst (dataframeDimensions df) |
| 35 | + in D.takeLast n df == df |
| 36 | + |
| 37 | +prop_dropLastAll :: DataFrame -> Bool |
| 38 | +prop_dropLastAll df = |
| 39 | + let n = fst (dataframeDimensions df) |
| 40 | + in fst (dataframeDimensions (D.dropLast n df)) == 0 |
| 41 | + |
| 42 | +prop_rangeEmpty :: DataFrame -> Bool |
| 43 | +prop_rangeEmpty df = |
| 44 | + fst (dataframeDimensions (D.range (5, 5) df)) == 0 |
| 45 | + |
| 46 | +prop_rangeFull :: DataFrame -> Bool |
| 47 | +prop_rangeFull df = |
| 48 | + let rows = fst (dataframeDimensions df) |
| 49 | + in D.range (0, rows) df == df |
| 50 | + |
| 51 | +prop_selectAll :: DataFrame -> Bool |
| 52 | +prop_selectAll df = D.select (D.columnNames df) df == df |
| 53 | + |
| 54 | +prop_selectEmpty :: DataFrame -> Bool |
| 55 | +prop_selectEmpty df = |
| 56 | + let result = D.select [] df |
| 57 | + in dataframeDimensions result == (0, 0) |
| 58 | + |
| 59 | +prop_excludeEmpty :: DataFrame -> Bool |
| 60 | +prop_excludeEmpty df = D.exclude [] df == df |
| 61 | + |
| 62 | +prop_excludeAll :: DataFrame -> Bool |
| 63 | +prop_excludeAll df = |
| 64 | + let result = D.exclude (D.columnNames df) df |
| 65 | + in snd (dataframeDimensions result) == 0 |
| 66 | + |
| 67 | +prop_cubePreservesSmall :: DataFrame -> Bool |
| 68 | +prop_cubePreservesSmall df = |
| 69 | + let (rows, cols) = dataframeDimensions df |
| 70 | + in D.cube (rows + 100, cols + 100) df == df |
| 71 | + |
| 72 | +prop_sampleEmptyApprox :: DataFrame -> Bool |
| 73 | +prop_sampleEmptyApprox df = |
| 74 | + let gen = mkStdGen 42 |
| 75 | + sampled = D.sample gen 0.0 df |
| 76 | + in fst (dataframeDimensions sampled) == 0 |
| 77 | + |
| 78 | +tests = |
| 79 | + [ prop_dropZero |
| 80 | + , prop_takeZero |
| 81 | + , prop_takeAll |
| 82 | + , prop_dropAll |
| 83 | + , prop_takeLastZero |
| 84 | + , prop_dropLastZero |
| 85 | + , prop_takeLastAll |
| 86 | + , prop_dropLastAll |
| 87 | + , prop_rangeEmpty |
| 88 | + , prop_rangeFull |
| 89 | + , prop_selectAll |
| 90 | + , prop_selectEmpty |
| 91 | + , prop_excludeEmpty |
| 92 | + , prop_excludeAll |
| 93 | + , prop_cubePreservesSmall |
| 94 | + , prop_sampleEmptyApprox |
| 95 | + ] |
0 commit comments