|
| 1 | +@testset "AbsoluteUnits" begin |
| 2 | + @test isrevertible(AbsoluteUnits()) |
| 3 | + |
| 4 | + a = [7, 4, 4, 7, 4, 1, 1, 6, 4, 7] * u"°C" |
| 5 | + b = [4, 5, 4, missing, 6, 6, missing, 4, 4, 1] * u"K" |
| 6 | + c = [3.9, 3.8, 3.5, 6.5, 7.7, 1.5, 0.6, 5.7, 4.7, 4.8] * u"K" |
| 7 | + d = [6.3, 4.7, 7.6, missing, 1.2, missing, 5.9, 0.2, 1.9, 4.2] * u"°C" |
| 8 | + e = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j"] |
| 9 | + t = Table(; a, b, c, d, e) |
| 10 | + |
| 11 | + T = AbsoluteUnits() |
| 12 | + n, c = apply(T, t) |
| 13 | + @test unit(eltype(n.a)) === u"K" |
| 14 | + @test unit(nonmissingtype(eltype(n.b))) === u"K" |
| 15 | + @test unit(eltype(n.c)) === u"K" |
| 16 | + @test unit(nonmissingtype(eltype(n.d))) === u"K" |
| 17 | + @test eltype(n.e) === String |
| 18 | + @test n.e == t.e |
| 19 | + tₒ = revert(T, n, c) |
| 20 | + @test t.a == tₒ.a |
| 21 | + @test isequal(t.b, tₒ.b) |
| 22 | + @test t.c == tₒ.c |
| 23 | + @test all(isapprox.(skipmissing(t.d), skipmissing(tₒ.d))) |
| 24 | + @test t.e == tₒ.e |
| 25 | + |
| 26 | + # args... |
| 27 | + # integers |
| 28 | + T = AbsoluteUnits(1, 2) |
| 29 | + n, c = apply(T, t) |
| 30 | + @test unit(eltype(n.a)) === u"K" |
| 31 | + @test unit(nonmissingtype(eltype(n.b))) === u"K" |
| 32 | + @test unit(eltype(n.c)) === u"K" |
| 33 | + @test unit(nonmissingtype(eltype(n.d))) === u"°C" |
| 34 | + tₒ = revert(T, n, c) |
| 35 | + @test t.a == tₒ.a |
| 36 | + @test isequal(t.b, tₒ.b) |
| 37 | + @test t.c == tₒ.c |
| 38 | + @test isequal(t.d, tₒ.d) |
| 39 | + @test t.e == tₒ.e |
| 40 | + |
| 41 | + # symbols |
| 42 | + T = AbsoluteUnits(:a, :b) |
| 43 | + n, c = apply(T, t) |
| 44 | + @test unit(eltype(n.a)) === u"K" |
| 45 | + @test unit(nonmissingtype(eltype(n.b))) === u"K" |
| 46 | + @test unit(eltype(n.c)) === u"K" |
| 47 | + @test unit(nonmissingtype(eltype(n.d))) === u"°C" |
| 48 | + tₒ = revert(T, n, c) |
| 49 | + @test t.a == tₒ.a |
| 50 | + @test isequal(t.b, tₒ.b) |
| 51 | + @test t.c == tₒ.c |
| 52 | + @test isequal(t.d, tₒ.d) |
| 53 | + @test t.e == tₒ.e |
| 54 | + |
| 55 | + # strings |
| 56 | + T = AbsoluteUnits("a", "b") |
| 57 | + n, c = apply(T, t) |
| 58 | + @test unit(eltype(n.a)) === u"K" |
| 59 | + @test unit(nonmissingtype(eltype(n.b))) === u"K" |
| 60 | + @test unit(eltype(n.c)) === u"K" |
| 61 | + @test unit(nonmissingtype(eltype(n.d))) === u"°C" |
| 62 | + tₒ = revert(T, n, c) |
| 63 | + @test t.a == tₒ.a |
| 64 | + @test isequal(t.b, tₒ.b) |
| 65 | + @test t.c == tₒ.c |
| 66 | + @test isequal(t.d, tₒ.d) |
| 67 | + @test t.e == tₒ.e |
| 68 | + |
| 69 | + # vector |
| 70 | + # integers |
| 71 | + T = AbsoluteUnits([3, 4]) |
| 72 | + n, c = apply(T, t) |
| 73 | + @test unit(eltype(n.a)) === u"°C" |
| 74 | + @test unit(nonmissingtype(eltype(n.b))) === u"K" |
| 75 | + @test unit(eltype(n.c)) === u"K" |
| 76 | + @test unit(nonmissingtype(eltype(n.d))) === u"K" |
| 77 | + tₒ = revert(T, n, c) |
| 78 | + @test t.a == tₒ.a |
| 79 | + @test isequal(t.b, tₒ.b) |
| 80 | + @test t.c == tₒ.c |
| 81 | + @test all(isapprox.(skipmissing(t.d), skipmissing(tₒ.d))) |
| 82 | + @test t.e == tₒ.e |
| 83 | + |
| 84 | + # symbols |
| 85 | + T = AbsoluteUnits([:c, :d]) |
| 86 | + n, c = apply(T, t) |
| 87 | + @test unit(eltype(n.a)) === u"°C" |
| 88 | + @test unit(nonmissingtype(eltype(n.b))) === u"K" |
| 89 | + @test unit(eltype(n.c)) === u"K" |
| 90 | + @test unit(nonmissingtype(eltype(n.d))) === u"K" |
| 91 | + tₒ = revert(T, n, c) |
| 92 | + @test t.a == tₒ.a |
| 93 | + @test isequal(t.b, tₒ.b) |
| 94 | + @test t.c == tₒ.c |
| 95 | + @test all(isapprox.(skipmissing(t.d), skipmissing(tₒ.d))) |
| 96 | + @test t.e == tₒ.e |
| 97 | + |
| 98 | + # strings |
| 99 | + T = AbsoluteUnits(["c", "d"]) |
| 100 | + n, c = apply(T, t) |
| 101 | + @test unit(eltype(n.a)) === u"°C" |
| 102 | + @test unit(nonmissingtype(eltype(n.b))) === u"K" |
| 103 | + @test unit(eltype(n.c)) === u"K" |
| 104 | + @test unit(nonmissingtype(eltype(n.d))) === u"K" |
| 105 | + tₒ = revert(T, n, c) |
| 106 | + @test t.a == tₒ.a |
| 107 | + @test isequal(t.b, tₒ.b) |
| 108 | + @test t.c == tₒ.c |
| 109 | + @test all(isapprox.(skipmissing(t.d), skipmissing(tₒ.d))) |
| 110 | + @test t.e == tₒ.e |
| 111 | + |
| 112 | + # tuple |
| 113 | + # integers |
| 114 | + T = AbsoluteUnits((1, 4, 5)) |
| 115 | + n, c = apply(T, t) |
| 116 | + @test unit(eltype(n.a)) === u"K" |
| 117 | + @test unit(nonmissingtype(eltype(n.b))) === u"K" |
| 118 | + @test unit(eltype(n.c)) === u"K" |
| 119 | + @test unit(nonmissingtype(eltype(n.d))) === u"K" |
| 120 | + @test eltype(n.e) === String |
| 121 | + @test n.e == t.e |
| 122 | + tₒ = revert(T, n, c) |
| 123 | + @test t.a == tₒ.a |
| 124 | + @test isequal(t.b, tₒ.b) |
| 125 | + @test t.c == tₒ.c |
| 126 | + @test all(isapprox.(skipmissing(t.d), skipmissing(tₒ.d))) |
| 127 | + @test t.e == tₒ.e |
| 128 | + |
| 129 | + # symbols |
| 130 | + T = AbsoluteUnits((:a, :d, :e)) |
| 131 | + n, c = apply(T, t) |
| 132 | + @test unit(eltype(n.a)) === u"K" |
| 133 | + @test unit(nonmissingtype(eltype(n.b))) === u"K" |
| 134 | + @test unit(eltype(n.c)) === u"K" |
| 135 | + @test unit(nonmissingtype(eltype(n.d))) === u"K" |
| 136 | + @test eltype(n.e) === String |
| 137 | + @test n.e == t.e |
| 138 | + tₒ = revert(T, n, c) |
| 139 | + @test t.a == tₒ.a |
| 140 | + @test isequal(t.b, tₒ.b) |
| 141 | + @test t.c == tₒ.c |
| 142 | + @test all(isapprox.(skipmissing(t.d), skipmissing(tₒ.d))) |
| 143 | + @test t.e == tₒ.e |
| 144 | + |
| 145 | + # strings |
| 146 | + T = AbsoluteUnits(("a", "d", "e")) |
| 147 | + n, c = apply(T, t) |
| 148 | + @test unit(eltype(n.a)) === u"K" |
| 149 | + @test unit(nonmissingtype(eltype(n.b))) === u"K" |
| 150 | + @test unit(eltype(n.c)) === u"K" |
| 151 | + @test unit(nonmissingtype(eltype(n.d))) === u"K" |
| 152 | + @test eltype(n.e) === String |
| 153 | + @test n.e == t.e |
| 154 | + tₒ = revert(T, n, c) |
| 155 | + @test t.a == tₒ.a |
| 156 | + @test isequal(t.b, tₒ.b) |
| 157 | + @test t.c == tₒ.c |
| 158 | + @test all(isapprox.(skipmissing(t.d), skipmissing(tₒ.d))) |
| 159 | + @test t.e == tₒ.e |
| 160 | + |
| 161 | + # regex |
| 162 | + T = AbsoluteUnits(r"[ade]") |
| 163 | + n, c = apply(T, t) |
| 164 | + @test unit(eltype(n.a)) === u"K" |
| 165 | + @test unit(nonmissingtype(eltype(n.b))) === u"K" |
| 166 | + @test unit(eltype(n.c)) === u"K" |
| 167 | + @test unit(nonmissingtype(eltype(n.d))) === u"K" |
| 168 | + @test eltype(n.e) === String |
| 169 | + @test n.e == t.e |
| 170 | + tₒ = revert(T, n, c) |
| 171 | + @test t.a == tₒ.a |
| 172 | + @test isequal(t.b, tₒ.b) |
| 173 | + @test t.c == tₒ.c |
| 174 | + @test all(isapprox.(skipmissing(t.d), skipmissing(tₒ.d))) |
| 175 | + @test t.e == tₒ.e |
| 176 | +end |
0 commit comments