| 1 | // Copyright (c) 2013-2014 Sandstorm Development Group, Inc. and contributorscxx . . $ `<file>/src/kj/units-test.c++`/ |
| 2 | // Licensed under the MIT License: |
| 3 | // |
| 4 | // Permission is hereby granted, free of charge, to any person obtaining a copy |
| 5 | // of this software and associated documentation files (the "Software"), to deal |
| 6 | // in the Software without restriction, including without limitation the rights |
| 7 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 8 | // copies of the Software, and to permit persons to whom the Software is |
| 9 | // furnished to do so, subject to the following conditions: |
| 10 | // |
| 11 | // The above copyright notice and this permission notice shall be included in |
| 12 | // all copies or substantial portions of the Software. |
| 13 | // |
| 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 17 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 19 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
| 20 | // THE SOFTWARE. |
| 21 | |
| 22 | #include "units.h"cxx . . $ `<file>/src/kj/units.h`/ |
| 23 | #include <kj/compat/gtest.h>cxx . . $ `<file>/src/kj/compat/gtest.h`/ |
| 24 | #include <iostream> |
| 25 | |
| 26 | namespace kjcxx . . $ kj/ { |
| 27 | namespacecxx . . $ kj/`$anonymous_namespace_src/kj/units-test.c++`/ { |
| 28 | |
| 29 | class Bytescxx . . $ kj/`$anonymous_namespace_src/kj/units-test.c++`/Bytes#; |
| 30 | class KiBcxx . . $ kj/`$anonymous_namespace_src/kj/units-test.c++`/KiB#; |
| 31 | class MiBcxx . . $ kj/`$anonymous_namespace_src/kj/units-test.c++`/MiB#; |
| 32 | |
| 33 | typedef Quantitycxx . . $ kj/Quantity#<int, Bytescxx . . $ kj/`$anonymous_namespace_src/kj/units-test.c++`/Bytes#> ByteCountcxx . . $ kj/`$anonymous_namespace_src/kj/units-test.c++`/ByteCount#; |
| 34 | typedef Quantitycxx . . $ kj/Quantity#<int, KiBcxx . . $ kj/`$anonymous_namespace_src/kj/units-test.c++`/KiB#> KiBCountcxx . . $ kj/`$anonymous_namespace_src/kj/units-test.c++`/KiBCount#; |
| 35 | typedef Quantitycxx . . $ kj/Quantity#<int, MiBcxx . . $ kj/`$anonymous_namespace_src/kj/units-test.c++`/MiB#> MiBCountcxx . . $ kj/`$anonymous_namespace_src/kj/units-test.c++`/MiBCount#; |
| 36 | |
| 37 | constexpr ByteCountcxx . . $ kj/`$anonymous_namespace_src/kj/units-test.c++`/ByteCount# BYTEcxx . . $ kj/`$anonymous_namespace_src/kj/units-test.c++`/BYTE. KJ_UNUSEDcxx . . $ `src/kj/common.h:249:9`! = unitcxx . . $ kj/unit(e3526cbfe7ff9a24).<ByteCountcxx . . $ kj/`$anonymous_namespace_src/kj/units-test.c++`/ByteCount#>(); |
| 38 | constexpr KiBCountcxx . . $ kj/`$anonymous_namespace_src/kj/units-test.c++`/KiBCount# KIBcxx . . $ kj/`$anonymous_namespace_src/kj/units-test.c++`/KIB. = unitcxx . . $ kj/unit(e3526cbfe7ff9a24).<KiBCountcxx . . $ kj/`$anonymous_namespace_src/kj/units-test.c++`/KiBCount#>(); |
| 39 | constexpr MiBCountcxx . . $ kj/`$anonymous_namespace_src/kj/units-test.c++`/MiBCount# MIBcxx . . $ kj/`$anonymous_namespace_src/kj/units-test.c++`/MIB. = unitcxx . . $ kj/unit(e3526cbfe7ff9a24).<MiBCountcxx . . $ kj/`$anonymous_namespace_src/kj/units-test.c++`/MiBCount#>(); |
| 40 | |
| 41 | constexpr UnitRatiocxx . . $ kj/UnitRatio#<int, Bytescxx . . $ kj/`$anonymous_namespace_src/kj/units-test.c++`/Bytes#, KiBcxx . . $ kj/`$anonymous_namespace_src/kj/units-test.c++`/KiB#> BYTES_PER_KIBcxx . . $ kj/`$anonymous_namespace_src/kj/units-test.c++`/BYTES_PER_KIB. KJ_UNUSEDcxx . . $ `src/kj/common.h:249:9`! = 1024 *cxx . . $ kj/`operator*`(42218075a680923e). BYTEcxx . . $ kj/`$anonymous_namespace_src/kj/units-test.c++`/BYTE. /cxx . . $ kj/Quantity#`operator/`(5c09fbadf976a583). KIBcxx . . $ kj/`$anonymous_namespace_src/kj/units-test.c++`/KIB.; |
| 42 | constexpr UnitRatiocxx . . $ kj/UnitRatio#<int, Bytescxx . . $ kj/`$anonymous_namespace_src/kj/units-test.c++`/Bytes#, MiBcxx . . $ kj/`$anonymous_namespace_src/kj/units-test.c++`/MiB#> BYTES_PER_MIBcxx . . $ kj/`$anonymous_namespace_src/kj/units-test.c++`/BYTES_PER_MIB. KJ_UNUSEDcxx . . $ `src/kj/common.h:249:9`! = 1024 * 1024 *cxx . . $ kj/`operator*`(42218075a680923e). BYTEcxx . . $ kj/`$anonymous_namespace_src/kj/units-test.c++`/BYTE. /cxx . . $ kj/Quantity#`operator/`(5c09fbadf976a583). MIBcxx . . $ kj/`$anonymous_namespace_src/kj/units-test.c++`/MIB.; |
| 43 | constexpr auto KIB_PER_MIBcxx . . $ kj/`$anonymous_namespace_src/kj/units-test.c++`/KIB_PER_MIB. = 1024 *cxx . . $ kj/`operator*`(42218075a680923e). KIBcxx . . $ kj/`$anonymous_namespace_src/kj/units-test.c++`/KIB. /cxx . . $ kj/Quantity#`operator/`(5c09fbadf976a583). MIBcxx . . $ kj/`$anonymous_namespace_src/kj/units-test.c++`/MIB.; |
| 44 | |
| 45 | template <typename T, typename U> |
| 46 | kjcxx . . $ kj/::Stringcxx . . $ kj/String# KJ_STRINGIFYcxx . . $ `src/kj/string.h:694:9`!(Quantity<T, U> value) { |
| 47 | return kjcxx . . $ kj/::strcxx . . $ kj/str(d4f75be60228bbc5).(value /cxx . . $ kj/`operator/`(60ee25129fca044a). unitcxx . . $ kj/unit(e3526cbfe7ff9a24).<Quantitycxx . . $ kj/Quantity#<T, U>>()); |
| 48 | } |
| 49 | |
| 50 | TESTcxx . . $ `src/kj/compat/gtest.h:120:9`!(UnitMeasure, Basics) { |
| 51 | KiBCountcxx . . $ kj/`$anonymous_namespace_src/kj/units-test.c++`/KiBCount# k = 15 *cxx . . $ kj/`operator*`(42218075a680923e). KIBcxx . . $ kj/`$anonymous_namespace_src/kj/units-test.c++`/KIB.; |
| 52 | EXPECT_EQcxx . . $ `src/kj/compat/gtest.h:56:9`!(15, k / KIB); |
| 53 | EXPECT_EQcxx . . $ `src/kj/compat/gtest.h:56:9`!(16 * KIB, k + KIB); |
| 54 | |
| 55 | k +=cxx . . $ kj/Quantity#`operator+=`(e0a33686f857e8). KIBcxx . . $ kj/`$anonymous_namespace_src/kj/units-test.c++`/KIB.; |
| 56 | k *=cxx . . $ kj/Quantity#`operator*=`(d615471b41290f40). 2048; |
| 57 | |
| 58 | EXPECT_EQcxx . . $ `src/kj/compat/gtest.h:56:9`!(32 * MIB, k / KIB_PER_MIB); |
| 59 | |
| 60 | EXPECT_TRUEcxx . . $ `src/kj/compat/gtest.h:55:9`!(2 * KIB < 4 * KIB); |
| 61 | EXPECT_FALSEcxx . . $ `src/kj/compat/gtest.h:54:9`!(8 * KIB < 4 * KIB); |
| 62 | } |
| 63 | |
| 64 | template <typename T, typename U> |
| 65 | static void assertSameTypecxx . . $ kj/`$anonymous_namespace_src/kj/units-test.c++`/assertSameType(49f6e7a06ebc5aa8).() { |
| 66 | U u; |
| 67 | T* t = &cxx . . $ kj/`operator&`(4e39d7611fbf5adb).u; |
| 68 | *t = 0; |
| 69 | } |
| 70 | |
| 71 | TESTcxx . . $ `src/kj/compat/gtest.h:120:9`!(UnitMeasure, AtLeastUInt) { |
| 72 | assertSameTypecxx . . $ kj/`$anonymous_namespace_src/kj/units-test.c++`/assertSameType(49f6e7a06ebc5aa8).<uint8_tcxx . . $ uint8_t# , AtLeastUIntcxx . . $ kj/AtLeastUInt#< 2>>(); |
| 73 | assertSameTypecxx . . $ kj/`$anonymous_namespace_src/kj/units-test.c++`/assertSameType(49f6e7a06ebc5aa8).<uint8_tcxx . . $ uint8_t# , AtLeastUIntcxx . . $ kj/AtLeastUInt#< 3>>(); |
| 74 | assertSameTypecxx . . $ kj/`$anonymous_namespace_src/kj/units-test.c++`/assertSameType(49f6e7a06ebc5aa8).<uint8_tcxx . . $ uint8_t# , AtLeastUIntcxx . . $ kj/AtLeastUInt#< 4>>(); |
| 75 | assertSameTypecxx . . $ kj/`$anonymous_namespace_src/kj/units-test.c++`/assertSameType(49f6e7a06ebc5aa8).<uint8_tcxx . . $ uint8_t# , AtLeastUIntcxx . . $ kj/AtLeastUInt#< 5>>(); |
| 76 | assertSameTypecxx . . $ kj/`$anonymous_namespace_src/kj/units-test.c++`/assertSameType(49f6e7a06ebc5aa8).<uint8_tcxx . . $ uint8_t# , AtLeastUIntcxx . . $ kj/AtLeastUInt#< 6>>(); |
| 77 | assertSameTypecxx . . $ kj/`$anonymous_namespace_src/kj/units-test.c++`/assertSameType(49f6e7a06ebc5aa8).<uint8_tcxx . . $ uint8_t# , AtLeastUIntcxx . . $ kj/AtLeastUInt#< 7>>(); |
| 78 | assertSameTypecxx . . $ kj/`$anonymous_namespace_src/kj/units-test.c++`/assertSameType(49f6e7a06ebc5aa8).<uint8_tcxx . . $ uint8_t# , AtLeastUIntcxx . . $ kj/AtLeastUInt#< 8>>(); |
| 79 | assertSameTypecxx . . $ kj/`$anonymous_namespace_src/kj/units-test.c++`/assertSameType(49f6e7a06ebc5aa8).<uint16_tcxx . . $ uint16_t#, AtLeastUIntcxx . . $ kj/AtLeastUInt#< 9>>(); |
| 80 | assertSameTypecxx . . $ kj/`$anonymous_namespace_src/kj/units-test.c++`/assertSameType(49f6e7a06ebc5aa8).<uint16_tcxx . . $ uint16_t#, AtLeastUIntcxx . . $ kj/AtLeastUInt#<10>>(); |
| 81 | assertSameTypecxx . . $ kj/`$anonymous_namespace_src/kj/units-test.c++`/assertSameType(49f6e7a06ebc5aa8).<uint16_tcxx . . $ uint16_t#, AtLeastUIntcxx . . $ kj/AtLeastUInt#<13>>(); |
| 82 | assertSameTypecxx . . $ kj/`$anonymous_namespace_src/kj/units-test.c++`/assertSameType(49f6e7a06ebc5aa8).<uint16_tcxx . . $ uint16_t#, AtLeastUIntcxx . . $ kj/AtLeastUInt#<16>>(); |
| 83 | assertSameTypecxx . . $ kj/`$anonymous_namespace_src/kj/units-test.c++`/assertSameType(49f6e7a06ebc5aa8).<uint32_tcxx . . $ uint32_t#, AtLeastUIntcxx . . $ kj/AtLeastUInt#<17>>(); |
| 84 | assertSameTypecxx . . $ kj/`$anonymous_namespace_src/kj/units-test.c++`/assertSameType(49f6e7a06ebc5aa8).<uint32_tcxx . . $ uint32_t#, AtLeastUIntcxx . . $ kj/AtLeastUInt#<23>>(); |
| 85 | assertSameTypecxx . . $ kj/`$anonymous_namespace_src/kj/units-test.c++`/assertSameType(49f6e7a06ebc5aa8).<uint32_tcxx . . $ uint32_t#, AtLeastUIntcxx . . $ kj/AtLeastUInt#<24>>(); |
| 86 | assertSameTypecxx . . $ kj/`$anonymous_namespace_src/kj/units-test.c++`/assertSameType(49f6e7a06ebc5aa8).<uint32_tcxx . . $ uint32_t#, AtLeastUIntcxx . . $ kj/AtLeastUInt#<25>>(); |
| 87 | assertSameTypecxx . . $ kj/`$anonymous_namespace_src/kj/units-test.c++`/assertSameType(49f6e7a06ebc5aa8).<uint32_tcxx . . $ uint32_t#, AtLeastUIntcxx . . $ kj/AtLeastUInt#<32>>(); |
| 88 | assertSameTypecxx . . $ kj/`$anonymous_namespace_src/kj/units-test.c++`/assertSameType(49f6e7a06ebc5aa8).<uint64_tcxx . . $ uint64_t#, AtLeastUIntcxx . . $ kj/AtLeastUInt#<33>>(); |
| 89 | assertSameTypecxx . . $ kj/`$anonymous_namespace_src/kj/units-test.c++`/assertSameType(49f6e7a06ebc5aa8).<uint64_tcxx . . $ uint64_t#, AtLeastUIntcxx . . $ kj/AtLeastUInt#<40>>(); |
| 90 | assertSameTypecxx . . $ kj/`$anonymous_namespace_src/kj/units-test.c++`/assertSameType(49f6e7a06ebc5aa8).<uint64_tcxx . . $ uint64_t#, AtLeastUIntcxx . . $ kj/AtLeastUInt#<41>>(); |
| 91 | assertSameTypecxx . . $ kj/`$anonymous_namespace_src/kj/units-test.c++`/assertSameType(49f6e7a06ebc5aa8).<uint64_tcxx . . $ uint64_t#, AtLeastUIntcxx . . $ kj/AtLeastUInt#<47>>(); |
| 92 | assertSameTypecxx . . $ kj/`$anonymous_namespace_src/kj/units-test.c++`/assertSameType(49f6e7a06ebc5aa8).<uint64_tcxx . . $ uint64_t#, AtLeastUIntcxx . . $ kj/AtLeastUInt#<48>>(); |
| 93 | assertSameTypecxx . . $ kj/`$anonymous_namespace_src/kj/units-test.c++`/assertSameType(49f6e7a06ebc5aa8).<uint64_tcxx . . $ uint64_t#, AtLeastUIntcxx . . $ kj/AtLeastUInt#<52>>(); |
| 94 | assertSameTypecxx . . $ kj/`$anonymous_namespace_src/kj/units-test.c++`/assertSameType(49f6e7a06ebc5aa8).<uint64_tcxx . . $ uint64_t#, AtLeastUIntcxx . . $ kj/AtLeastUInt#<64>>(); |
| 95 | |
| 96 | // COMPILE ERROR: assertSameType<uint64_t, AtLeastUInt<65>>(); |
| 97 | } |
| 98 | |
| 99 | TESTcxx . . $ `src/kj/compat/gtest.h:120:9`!(UnitMeasure, BoundedConst) { |
| 100 | // TODO(someday): Some script should attempt to compile this test once with each "COMPILE ERROR" |
| 101 | // line restored to verify that they actually error out. |
| 102 | |
| 103 | KJ_EXPECTcxx . . $ `src/kj/test.h:92:9`!((bounded<456>() + bounded<123>()).unwrap() == 456 + 123); |
| 104 | KJ_EXPECTcxx . . $ `src/kj/test.h:92:9`!((bounded<456>() - bounded<123>()).unwrap() == 456 - 123); |
| 105 | KJ_EXPECTcxx . . $ `src/kj/test.h:92:9`!((bounded<456>() * bounded<123>()).unwrap() == 456 * 123); |
| 106 | KJ_EXPECTcxx . . $ `src/kj/test.h:92:9`!((bounded<456>() / bounded<123>()).unwrap() == 456 / 123); |
| 107 | KJ_EXPECTcxx . . $ `src/kj/test.h:92:9`!((bounded<456>() % bounded<123>()).unwrap() == 456 % 123); |
| 108 | KJ_EXPECTcxx . . $ `src/kj/test.h:92:9`!((bounded<456>() << bounded<5>()).unwrap() == 456 << 5); |
| 109 | KJ_EXPECTcxx . . $ `src/kj/test.h:92:9`!((bounded<456>() >> bounded<2>()).unwrap() == 456 >> 2); |
| 110 | |
| 111 | KJ_EXPECTcxx . . $ `src/kj/test.h:92:9`!(bounded<123>() == bounded<123>()); |
| 112 | KJ_EXPECTcxx . . $ `src/kj/test.h:92:9`!(bounded<123>() != bounded<456>()); |
| 113 | KJ_EXPECTcxx . . $ `src/kj/test.h:92:9`!(bounded<123>() < bounded<456>()); |
| 114 | KJ_EXPECTcxx . . $ `src/kj/test.h:92:9`!(bounded<456>() > bounded<123>()); |
| 115 | KJ_EXPECTcxx . . $ `src/kj/test.h:92:9`!(bounded<123>() <= bounded<456>()); |
| 116 | KJ_EXPECTcxx . . $ `src/kj/test.h:92:9`!(bounded<456>() >= bounded<123>()); |
| 117 | |
| 118 | KJ_EXPECTcxx . . $ `src/kj/test.h:92:9`!(!(bounded<123>() == bounded<456>())); |
| 119 | KJ_EXPECTcxx . . $ `src/kj/test.h:92:9`!(!(bounded<123>() != bounded<123>())); |
| 120 | KJ_EXPECTcxx . . $ `src/kj/test.h:92:9`!(!(bounded<456>() < bounded<123>())); |
| 121 | KJ_EXPECTcxx . . $ `src/kj/test.h:92:9`!(!(bounded<123>() > bounded<456>())); |
| 122 | KJ_EXPECTcxx . . $ `src/kj/test.h:92:9`!(!(bounded<456>() <= bounded<123>())); |
| 123 | KJ_EXPECTcxx . . $ `src/kj/test.h:92:9`!(!(bounded<123>() >= bounded<456>())); |
| 124 | |
| 125 | { |
| 126 | uint16_tcxx . . $ uint16_t# succ = unboundcxx . . $ kj/unbound(b5a4eeda48c236b0).(boundedcxx . . $ kj/bounded(a028f20150fac02e).<12345>()); |
| 127 | KJ_EXPECTcxx . . $ `src/kj/test.h:92:9`!(succ == 12345); |
| 128 | |
| 129 | // COMPILE ERROR: uint8_t err KJ_UNUSED = unbound(bounded<12345>()); |
| 130 | } |
| 131 | |
| 132 | // COMPILE ERROR: auto err1 KJ_UNUSED = bounded<(0xffffffffffffffffull)>() + bounded<1>(); |
| 133 | // COMPILE ERROR: auto err2 KJ_UNUSED = bounded<1>() - bounded<2>(); |
| 134 | // COMPILE ERROR: auto err3 KJ_UNUSED = bounded<(1ull << 60)>() * bounded<(1ull << 60)>(); |
| 135 | // COMPILE ERROR: auto err4 KJ_UNUSED = bounded<1>() / bounded<0>(); |
| 136 | // COMPILE ERROR: auto err5 KJ_UNUSED = bounded<1>() % bounded<0>(); |
| 137 | // COMPILE ERROR: auto err6 KJ_UNUSED = bounded<1>() << bounded<64>(); |
| 138 | // COMPILE ERROR: auto err7 KJ_UNUSED = bounded<(1ull << 60)>() << bounded<4>(); |
| 139 | // COMPILE ERROR: auto err8 KJ_UNUSED = bounded<1>() >> bounded<64>(); |
| 140 | |
| 141 | // COMPILE ERROR: boundedAdd<0xffffffffffffffffull, 1>(); |
| 142 | // COMPILE ERROR: boundedSub<1, 2>(); |
| 143 | // COMPILE ERROR: boundedMul<0x100000000, 0x100000000>(); |
| 144 | // COMPILE ERROR: boundedLShift<0x10, 60>(); |
| 145 | } |
| 146 | |
| 147 | template <uintcxx . . $ kj/uint# value, typename T = uintcxx . . $ kj/uint#> |
| 148 | constexpr Boundedcxx . . $ kj/Bounded#<value, T> boundedValuecxx . . $ kj/`$anonymous_namespace_src/kj/units-test.c++`/boundedValue(13148ffb1ffed4b9).(NoInfercxx . . $ kj/NoInfer#<T> runtimeValue = value) { |
| 149 | return Boundedcxx . . $ kj/Bounded#<value, T>(runtimeValue, unsafecxx . . $ kj/unsafe.); |
| 150 | } |
| 151 | |
| 152 | TESTcxx . . $ `src/kj/compat/gtest.h:120:9`!(UnitMeasure, Bounded) { |
| 153 | // TODO(someday): Some script should attempt to compile this test once with each "COMPILE ERROR" |
| 154 | // line restored to verify that they actually error out. |
| 155 | |
| 156 | KJ_EXPECTcxx . . $ `src/kj/test.h:92:9`!((boundedValue<456>() + boundedValue<123>()).unwrap() == 456 + 123); |
| 157 | KJ_EXPECTcxx . . $ `src/kj/test.h:92:9`!(boundedValue<456>().subtractChecked(boundedValue<123>(), [](){}).unwrap() == 456 - 123); |
| 158 | KJ_EXPECTcxx . . $ `src/kj/test.h:92:9`!((boundedValue<456>() * boundedValue<123>()).unwrap() == 456 * 123); |
| 159 | KJ_EXPECTcxx . . $ `src/kj/test.h:92:9`!((boundedValue<456>() / boundedValue<123>()).unwrap() == 456 / 123); |
| 160 | KJ_EXPECTcxx . . $ `src/kj/test.h:92:9`!((boundedValue<456>() % boundedValue<123>()).unwrap() == 456 % 123); |
| 161 | |
| 162 | |
| 163 | { |
| 164 | Boundedcxx . . $ kj/Bounded#<123, uint8_tcxx . . $ uint8_t#> succcxx . . $ kj/Bounded#Bounded(49f6e7a06ebc5aa8). KJ_UNUSEDcxx . . $ `src/kj/common.h:249:9`!; |
| 165 | // COMPILE ERROR: Bounded<1234, uint8_t> err KJ_UNUSED; |
| 166 | // COMPILE ERROR: auto err KJ_UNUSED = boundedValue<0xffffffffull>() + boundedValue<1>(); |
| 167 | } |
| 168 | |
| 169 | { |
| 170 | Boundedcxx . . $ kj/Bounded#<123, uint8_tcxx . . $ uint8_t#> succ1 KJ_UNUSEDcxx . . $ `src/kj/common.h:249:9`! = boundedValuecxx . . $ kj/Bounded#Bounded(be213d4be11c777a).<123>(); |
| 171 | Boundedcxx . . $ kj/Bounded#<123, uint8_tcxx . . $ uint8_t#> succ2 KJ_UNUSEDcxx . . $ `src/kj/common.h:249:9`! = boundedValuecxx . . $ kj/Bounded#Bounded(be213d4be11c777a).<122>(); |
| 172 | Boundedcxx . . $ kj/Bounded#<123, uint8_tcxx . . $ uint8_t#> succ3 KJ_UNUSEDcxx . . $ `src/kj/common.h:249:9`! = boundedValuecxx . . $ kj/Bounded#Bounded(be213d4be11c777a).<0>(); |
| 173 | // COMPILE ERROR: Bounded<123, uint8_t> err KJ_UNUSED = boundedValue<124>(); |
| 174 | // COMPILE ERROR: Bounded<123, uint8_t> err KJ_UNUSED = boundedValue<125>(); |
| 175 | // COMPILE ERROR: Bounded<123, uint8_t> err KJ_UNUSED = boundedValue<123456>(); |
| 176 | } |
| 177 | |
| 178 | Boundedcxx . . $ kj/Bounded#<123, uint8_tcxx . . $ uint8_t#> foocxx . . $ kj/Bounded#Bounded(49f6e7a06ebc5aa8).; |
| 179 | foo =cxx . . $ kj/Bounded#`operator=`(3dce72453596e5cd). boundedValuecxx . . $ kj/`$anonymous_namespace_src/kj/units-test.c++`/boundedValue(13148ffb1ffed4b9).<123>(); |
| 180 | foo =cxx . . $ kj/Bounded#`operator=`(3dce72453596e5cd). boundedValuecxx . . $ kj/`$anonymous_namespace_src/kj/units-test.c++`/boundedValue(13148ffb1ffed4b9).<122>(); |
| 181 | foo =cxx . . $ kj/Bounded#`operator=`(3dce72453596e5cd). boundedValuecxx . . $ kj/`$anonymous_namespace_src/kj/units-test.c++`/boundedValue(13148ffb1ffed4b9).<0>(); |
| 182 | // COMPILE ERROR: foo = boundedValue<124>(); |
| 183 | // COMPILE ERROR: foo = boundedValue<125>(); |
| 184 | // COMPILE ERROR: foo = boundedValue<123456>(); |
| 185 | |
| 186 | assertMaxcxx . . $ kj/assertMax(145834b5f7e0c943).<122>(foocxx . . $ kj/Bounded#Bounded(34fb647f4baa42e1)., []() {}); |
| 187 | // COMPILE ERROR: assertMax<123>(foo, []() {}); |
| 188 | // COMPILE ERROR: assertMax<124>(foo, []() {}); |
| 189 | |
| 190 | assertMaxBitscxx . . $ kj/assertMaxBits(97cd9162ab772a29).<6>(foocxx . . $ kj/Bounded#Bounded(34fb647f4baa42e1)., []() {}); |
| 191 | // COMPILE ERROR: assertMaxBits<7>(foo, []() {}); |
| 192 | // COMPILE ERROR: assertMaxBits<8>(foo, []() {}); |
| 193 | |
| 194 | Boundedcxx . . $ kj/Bounded#<12, uint8_tcxx . . $ uint8_t#> barcxx . . $ kj/Bounded#Bounded(49f6e7a06ebc5aa8).; |
| 195 | // COMPILE ERROR: bar = foo; |
| 196 | // COMPILE ERROR: bar = foo.assertMax<13>([]() {}); |
| 197 | bool caught = false; |
| 198 | foo =cxx . . $ kj/Bounded#`operator=`(3dce72453596e5cd). boundedValuecxx . . $ kj/`$anonymous_namespace_src/kj/units-test.c++`/boundedValue(13148ffb1ffed4b9).<13>(); |
| 199 | bar =cxx . . $ kj/Bounded#`operator=`(9d96c777cf6986fc). foo.assertMaxcxx . . $ kj/Bounded#assertMax(ada31d9d03f2ebbc).<12>([&]() { caught = true; }); |
| 200 | KJ_EXPECTcxx . . $ `src/kj/test.h:92:9`!(caught); |
| 201 | |
| 202 | foo =cxx . . $ kj/Bounded#`operator=`(3dce72453596e5cd). boundedValuecxx . . $ kj/`$anonymous_namespace_src/kj/units-test.c++`/boundedValue(13148ffb1ffed4b9).<100>() +cxx . . $ kj/Bounded#operator+(418112557ed71c5c). boundedValuecxx . . $ kj/`$anonymous_namespace_src/kj/units-test.c++`/boundedValue(13148ffb1ffed4b9).<23>(); |
| 203 | // COMPILE ERROR: foo = boundedValue<100>() + boundedValue<24>(); |
| 204 | |
| 205 | bar =cxx . . $ kj/Bounded#`operator=`(3dce72453596e5cd). boundedValuecxx . . $ kj/`$anonymous_namespace_src/kj/units-test.c++`/boundedValue(13148ffb1ffed4b9).<3>() *cxx . . $ kj/Bounded#`operator*`(2ba64529522823ab). boundedValuecxx . . $ kj/`$anonymous_namespace_src/kj/units-test.c++`/boundedValue(13148ffb1ffed4b9).<4>(); |
| 206 | // COMPILE ERROR: bar = boundedValue<2>() * boundedValue<7>(); |
| 207 | |
| 208 | foo.subtractCheckedcxx . . $ kj/Bounded#subtractChecked(4cf53f6d51ed8442).(boundedValuecxx . . $ kj/`$anonymous_namespace_src/kj/units-test.c++`/boundedValue(13148ffb1ffed4b9).<122>(), []() { KJ_FAIL_EXPECTcxx . . $ `src/kj/test.h:90:9`!(""); }); |
| 209 | foo.subtractCheckedcxx . . $ kj/Bounded#subtractChecked(4cf53f6d51ed8442).(boundedValuecxx . . $ kj/`$anonymous_namespace_src/kj/units-test.c++`/boundedValue(13148ffb1ffed4b9).<123>(), []() { KJ_FAIL_EXPECTcxx . . $ `src/kj/test.h:90:9`!(""); }); |
| 210 | caught = false; |
| 211 | foo.subtractCheckedcxx . . $ kj/Bounded#subtractChecked(4cf53f6d51ed8442).(boundedValuecxx . . $ kj/`$anonymous_namespace_src/kj/units-test.c++`/boundedValue(13148ffb1ffed4b9).<124>(), [&]() { caught = true; }); |
| 212 | KJ_EXPECTcxx . . $ `src/kj/test.h:92:9`!(caught); |
| 213 | |
| 214 | { |
| 215 | Boundedcxx . . $ kj/Bounded#<65535, uint16_tcxx . . $ uint16_t#> succ1 KJ_UNUSEDcxx . . $ `src/kj/common.h:249:9`! = boundedcxx . . $ kj/bounded(6b09f0fd326d20a6).((uint16_tcxx . . $ uint16_t#)123); |
| 216 | // COMPILE ERROR: Bounded<65534, uint16_t> err KJ_UNUSED = bounded((uint16_t)123); |
| 217 | } |
| 218 | |
| 219 | uintcxx . . $ kj/uint# old = foo.unwrapcxx . . $ kj/Bounded#unwrap(7b7646ca7c721626).(); |
| 220 | foo =cxx . . $ kj/Bounded#`operator=`(3dce72453596e5cd). foocxx . . $ kj/Bounded#Bounded(34fb647f4baa42e1). *cxx . . $ kj/`operator*`(9a01455975bfe2ec). unitcxx . . $ kj/unit(e3526cbfe7ff9a24).<decltype(foo)>(); |
| 221 | KJ_EXPECTcxx . . $ `src/kj/test.h:92:9`!(foo.unwrap() == old); |
| 222 | |
| 223 | { |
| 224 | Boundedcxx . . $ kj/Bounded#<1234, uint16_tcxx . . $ uint16_t#> x = boundedcxx . . $ kj/Bounded#Bounded(5b25d73b6d0b7706).<123>(); |
| 225 | uint16_tcxx . . $ uint16_t# succ = unboundcxx . . $ kj/unbound(5db8983d14346740).(xcxx . . $ kj/Bounded#Bounded(34fb647f4baa42e1).); |
| 226 | KJ_EXPECTcxx . . $ `src/kj/test.h:92:9`!(succ == 123); |
| 227 | |
| 228 | // COMPILE ERROR: uint8_t err KJ_UNUSED = unbound(x); |
| 229 | } |
| 230 | } |
| 231 | |
| 232 | TESTcxx . . $ `src/kj/compat/gtest.h:120:9`!(UnitMeasure, BoundedVsGuardedConst) { |
| 233 | // TODO(someday): Some script should attempt to compile this test once with each "COMPILE ERROR" |
| 234 | // line restored to verify that they actually error out. |
| 235 | |
| 236 | KJ_EXPECTcxx . . $ `src/kj/test.h:92:9`!((boundedValue<456>() + bounded<123>()).unwrap() == 456 + 123); |
| 237 | KJ_EXPECTcxx . . $ `src/kj/test.h:92:9`!(boundedValue<456>().subtractChecked(bounded<123>(), [](){}).unwrap() == 456 - 123); |
| 238 | KJ_EXPECTcxx . . $ `src/kj/test.h:92:9`!((boundedValue<456>() * bounded<123>()).unwrap() == 456 * 123); |
| 239 | KJ_EXPECTcxx . . $ `src/kj/test.h:92:9`!((boundedValue<456>() / bounded<123>()).unwrap() == 456 / 123); |
| 240 | KJ_EXPECTcxx . . $ `src/kj/test.h:92:9`!((boundedValue<456>() % bounded<123>()).unwrap() == 456 % 123); |
| 241 | |
| 242 | { |
| 243 | Boundedcxx . . $ kj/Bounded#<123, uint8_tcxx . . $ uint8_t#> succ1 KJ_UNUSEDcxx . . $ `src/kj/common.h:249:9`! = boundedcxx . . $ kj/Bounded#Bounded(5b25d73b6d0b7706).<123>(); |
| 244 | Boundedcxx . . $ kj/Bounded#<123, uint8_tcxx . . $ uint8_t#> succ2 KJ_UNUSEDcxx . . $ `src/kj/common.h:249:9`! = boundedcxx . . $ kj/Bounded#Bounded(5b25d73b6d0b7706).<122>(); |
| 245 | Boundedcxx . . $ kj/Bounded#<123, uint8_tcxx . . $ uint8_t#> succ3 KJ_UNUSEDcxx . . $ `src/kj/common.h:249:9`! = boundedcxx . . $ kj/Bounded#Bounded(5b25d73b6d0b7706).<0>(); |
| 246 | // COMPILE ERROR: Bounded<123, uint8_t> err KJ_UNUSED = bounded<124>(); |
| 247 | // COMPILE ERROR: Bounded<123, uint8_t> err KJ_UNUSED = bounded<125>(); |
| 248 | // COMPILE ERROR: Bounded<123, uint8_t> err KJ_UNUSED = bounded<123456>(); |
| 249 | } |
| 250 | |
| 251 | Boundedcxx . . $ kj/Bounded#<123, uint8_tcxx . . $ uint8_t#> foocxx . . $ kj/Bounded#Bounded(49f6e7a06ebc5aa8).; |
| 252 | foo =cxx . . $ kj/Bounded#`operator=`(7258038f3870dbce). boundedcxx . . $ kj/bounded(a028f20150fac02e).<123>(); |
| 253 | foo =cxx . . $ kj/Bounded#`operator=`(7258038f3870dbce). boundedcxx . . $ kj/bounded(a028f20150fac02e).<122>(); |
| 254 | foo =cxx . . $ kj/Bounded#`operator=`(7258038f3870dbce). boundedcxx . . $ kj/bounded(a028f20150fac02e).<0>(); |
| 255 | // COMPILE ERROR: foo = bounded<124>(); |
| 256 | // COMPILE ERROR: foo = bounded<125>(); |
| 257 | // COMPILE ERROR: foo = bounded<123456>(); |
| 258 | |
| 259 | Boundedcxx . . $ kj/Bounded#<16, uint8_tcxx . . $ uint8_t#> barcxx . . $ kj/Bounded#Bounded(49f6e7a06ebc5aa8).; |
| 260 | // COMPILE ERROR: bar = foo >> bounded<2>(); |
| 261 | bar =cxx . . $ kj/Bounded#`operator=`(3dce72453596e5cd). foocxx . . $ kj/Bounded#Bounded(34fb647f4baa42e1). >>cxx . . $ kj/`operator>>`(cd247645dbca3816). boundedcxx . . $ kj/bounded(a028f20150fac02e).<3>(); |
| 262 | |
| 263 | // COMPILE ERROR: foo = bar << bounded<3>(); |
| 264 | foo =cxx . . $ kj/Bounded#`operator=`(3dce72453596e5cd). barcxx . . $ kj/Bounded#Bounded(34fb647f4baa42e1). <<cxx . . $ kj/`operator<<`(292470bfbc6cf3fb). boundedcxx . . $ kj/bounded(a028f20150fac02e).<2>(); |
| 265 | } |
| 266 | |
| 267 | TESTcxx . . $ `src/kj/compat/gtest.h:120:9`!(UnitMeasure, BoundedRange) { |
| 268 | uintcxx . . $ kj/uint# expected = 0; |
| 269 | for (auto i: zeroTocxx . . $ kj/zeroTo(9a86f08902b817d).(boundedcxx . . $ kj/bounded(a028f20150fac02e).<10>())) { |
| 270 | Boundedcxx . . $ kj/Bounded#<10, uint8_tcxx . . $ uint8_t#> value = icxx . . $ kj/Bounded#Bounded(be213d4be11c777a).; |
| 271 | KJ_EXPECTcxx . . $ `src/kj/test.h:92:9`!(unbound(value) == expected++); |
| 272 | } |
| 273 | KJ_EXPECTcxx . . $ `src/kj/test.h:92:9`!(expected == 10); |
| 274 | |
| 275 | expected = 0; |
| 276 | for (auto i: zeroTocxx . . $ kj/zeroTo(79d3e41e5132f71a).(boundedcxx . . $ kj/bounded(6b09f0fd326d20a6).((uint8_tcxx . . $ uint8_t#)10))) { |
| 277 | Boundedcxx . . $ kj/Bounded#<255, uint8_tcxx . . $ uint8_t#> value = icxx . . $ kj/Bounded#Bounded(34fb647f4baa42e1).; |
| 278 | KJ_EXPECTcxx . . $ `src/kj/test.h:92:9`!(unbound(value) == expected++); |
| 279 | } |
| 280 | KJ_EXPECTcxx . . $ `src/kj/test.h:92:9`!(expected == 10); |
| 281 | |
| 282 | expected = 3; |
| 283 | for (auto i: rangecxx . . $ kj/range(7e3323aa3de23b55).(boundedcxx . . $ kj/bounded(6b09f0fd326d20a6).((uint8_tcxx . . $ uint8_t#)3), boundedcxx . . $ kj/bounded(6b09f0fd326d20a6).((uint8_tcxx . . $ uint8_t#)10))) { |
| 284 | Boundedcxx . . $ kj/Bounded#<255, uint8_tcxx . . $ uint8_t#> value = icxx . . $ kj/Bounded#Bounded(34fb647f4baa42e1).; |
| 285 | KJ_EXPECTcxx . . $ `src/kj/test.h:92:9`!(unbound(value) == expected++); |
| 286 | } |
| 287 | KJ_EXPECTcxx . . $ `src/kj/test.h:92:9`!(expected == 10); |
| 288 | } |
| 289 | |
| 290 | TESTcxx . . $ `src/kj/compat/gtest.h:120:9`!(UnitMeasure, BoundedQuantity) { |
| 291 | auto BYTES = unitcxx . . $ kj/unit(e3526cbfe7ff9a24).<Quantitycxx . . $ kj/Quantity#<Boundedcxx . . $ kj/Bounded#<12345, uint16_tcxx . . $ uint16_t#>, bytecxx . . $ kj/byte#>>(); |
| 292 | |
| 293 | uintcxx . . $ kj/uint# expected = 0; |
| 294 | for (auto i: zeroTocxx . . $ kj/zeroTo(ce96a627f1de0424).(boundedcxx . . $ kj/bounded(a028f20150fac02e).<10>() *cxx . . $ kj/`operator*`(42218075a680923e). BYTES)) { |
| 295 | Quantitycxx . . $ kj/Quantity#<Boundedcxx . . $ kj/Bounded#<10, uint8_tcxx . . $ uint8_t#>, bytecxx . . $ kj/byte#> value = icxx . . $ kj/Quantity#Quantity(5c37695be3ed1b49).; |
| 296 | KJ_EXPECTcxx . . $ `src/kj/test.h:92:9`!(unbound(value / BYTES) == expected++); |
| 297 | } |
| 298 | KJ_EXPECTcxx . . $ `src/kj/test.h:92:9`!(expected == 10); |
| 299 | |
| 300 | expected = 0; |
| 301 | for (auto i: zeroTocxx . . $ kj/zeroTo(79d3e41e5132f71a).(boundedcxx . . $ kj/bounded(6b09f0fd326d20a6).((uint8_tcxx . . $ uint8_t#)10) *cxx . . $ kj/`operator*`(42218075a680923e). BYTES)) { |
| 302 | Quantitycxx . . $ kj/Quantity#<Boundedcxx . . $ kj/Bounded#<255, uint8_tcxx . . $ uint8_t#>, bytecxx . . $ kj/byte#> value = icxx . . $ kj/Quantity#Quantity(5c37695be3ed1b49).; |
| 303 | KJ_EXPECTcxx . . $ `src/kj/test.h:92:9`!(unbound(value / BYTES) == expected++); |
| 304 | } |
| 305 | KJ_EXPECTcxx . . $ `src/kj/test.h:92:9`!(expected == 10); |
| 306 | |
| 307 | expected = 3; |
| 308 | for (auto i: rangecxx . . $ kj/range(7e3323aa3de23b55).(boundedcxx . . $ kj/bounded(6b09f0fd326d20a6).((uint8_tcxx . . $ uint8_t#)3) *cxx . . $ kj/`operator*`(42218075a680923e). BYTES, boundedcxx . . $ kj/bounded(6b09f0fd326d20a6).((uint8_tcxx . . $ uint8_t#)10) *cxx . . $ kj/`operator*`(42218075a680923e). BYTES)) { |
| 309 | Quantitycxx . . $ kj/Quantity#<Boundedcxx . . $ kj/Bounded#<255, uint8_tcxx . . $ uint8_t#>, bytecxx . . $ kj/byte#> value = icxx . . $ kj/Quantity#Quantity(5c37695be3ed1b49).; |
| 310 | KJ_EXPECTcxx . . $ `src/kj/test.h:92:9`!(unbound(value / BYTES) == expected++); |
| 311 | } |
| 312 | KJ_EXPECTcxx . . $ `src/kj/test.h:92:9`!(expected == 10); |
| 313 | } |
| 314 | |
| 315 | template <typename T> |
| 316 | void assertTypeAndValuecxx . . $ kj/`$anonymous_namespace_src/kj/units-test.c++`/assertTypeAndValue(249673c20e2b8d5).(T a, T b) { KJ_EXPECTcxx . . $ `src/kj/test.h:92:9`!(a == b); } |
| 317 | |
| 318 | TESTcxx . . $ `src/kj/compat/gtest.h:120:9`!(UnitMeasure, BoundedMinMax) { |
| 319 | assertTypeAndValuecxx . . $ kj/`$anonymous_namespace_src/kj/units-test.c++`/assertTypeAndValue(249673c20e2b8d5).(boundedcxx . . $ kj/bounded(a028f20150fac02e).<5>(), kjcxx . . $ kj/::maxcxx . . $ kj/max(964f4bc678facaae).(boundedcxx . . $ kj/bounded(a028f20150fac02e).<4>(), boundedcxx . . $ kj/bounded(a028f20150fac02e).<5>())); |
| 320 | assertTypeAndValuecxx . . $ kj/`$anonymous_namespace_src/kj/units-test.c++`/assertTypeAndValue(249673c20e2b8d5).(boundedcxx . . $ kj/bounded(a028f20150fac02e).<5>(), kjcxx . . $ kj/::maxcxx . . $ kj/max(964f4bc678facaae).(boundedcxx . . $ kj/bounded(a028f20150fac02e).<5>(), boundedcxx . . $ kj/bounded(a028f20150fac02e).<4>())); |
| 321 | assertTypeAndValuecxx . . $ kj/`$anonymous_namespace_src/kj/units-test.c++`/assertTypeAndValue(249673c20e2b8d5).(boundedcxx . . $ kj/bounded(a028f20150fac02e).<4>(), kjcxx . . $ kj/::maxcxx . . $ kj/max(964f4bc678facaae).(boundedcxx . . $ kj/bounded(a028f20150fac02e).<4>(), boundedcxx . . $ kj/bounded(a028f20150fac02e).<4>())); |
| 322 | |
| 323 | assertTypeAndValuecxx . . $ kj/`$anonymous_namespace_src/kj/units-test.c++`/assertTypeAndValue(249673c20e2b8d5).(boundedcxx . . $ kj/bounded(a028f20150fac02e).<4>(), kjcxx . . $ kj/::mincxx . . $ kj/min(cd27e3a74fa8f55c).(boundedcxx . . $ kj/bounded(a028f20150fac02e).<4>(), boundedcxx . . $ kj/bounded(a028f20150fac02e).<5>())); |
| 324 | assertTypeAndValuecxx . . $ kj/`$anonymous_namespace_src/kj/units-test.c++`/assertTypeAndValue(249673c20e2b8d5).(boundedcxx . . $ kj/bounded(a028f20150fac02e).<4>(), kjcxx . . $ kj/::mincxx . . $ kj/min(cd27e3a74fa8f55c).(boundedcxx . . $ kj/bounded(a028f20150fac02e).<5>(), boundedcxx . . $ kj/bounded(a028f20150fac02e).<4>())); |
| 325 | assertTypeAndValuecxx . . $ kj/`$anonymous_namespace_src/kj/units-test.c++`/assertTypeAndValue(249673c20e2b8d5).(boundedcxx . . $ kj/bounded(a028f20150fac02e).<4>(), kjcxx . . $ kj/::mincxx . . $ kj/min(cd27e3a74fa8f55c).(boundedcxx . . $ kj/bounded(a028f20150fac02e).<4>(), boundedcxx . . $ kj/bounded(a028f20150fac02e).<4>())); |
| 326 | |
| 327 | typedef uint8_tcxx . . $ uint8_t# t1cxx . . $ kj/`$anonymous_namespace_src/kj/units-test.c++`/TestCase318#run(49f6e7a06ebc5aa8).t1#; |
| 328 | typedef uint16_tcxx . . $ uint16_t# t2cxx . . $ kj/`$anonymous_namespace_src/kj/units-test.c++`/TestCase318#run(49f6e7a06ebc5aa8).t2#; |
| 329 | |
| 330 | assertTypeAndValuecxx . . $ kj/`$anonymous_namespace_src/kj/units-test.c++`/assertTypeAndValue(249673c20e2b8d5).(boundedValuecxx . . $ kj/`$anonymous_namespace_src/kj/units-test.c++`/boundedValue(13148ffb1ffed4b9).<5,t2cxx . . $ kj/`$anonymous_namespace_src/kj/units-test.c++`/TestCase318#run(49f6e7a06ebc5aa8).t2#>(3), kjcxx . . $ kj/::maxcxx . . $ kj/max(97a3da08354c71ff).(boundedValuecxx . . $ kj/`$anonymous_namespace_src/kj/units-test.c++`/boundedValue(13148ffb1ffed4b9).<4,t2cxx . . $ kj/`$anonymous_namespace_src/kj/units-test.c++`/TestCase318#run(49f6e7a06ebc5aa8).t2#>(3), boundedValuecxx . . $ kj/`$anonymous_namespace_src/kj/units-test.c++`/boundedValue(13148ffb1ffed4b9).<5,t1cxx . . $ kj/`$anonymous_namespace_src/kj/units-test.c++`/TestCase318#run(49f6e7a06ebc5aa8).t1#>(2))); |
| 331 | assertTypeAndValuecxx . . $ kj/`$anonymous_namespace_src/kj/units-test.c++`/assertTypeAndValue(249673c20e2b8d5).(boundedValuecxx . . $ kj/`$anonymous_namespace_src/kj/units-test.c++`/boundedValue(13148ffb1ffed4b9).<5,t2cxx . . $ kj/`$anonymous_namespace_src/kj/units-test.c++`/TestCase318#run(49f6e7a06ebc5aa8).t2#>(3), kjcxx . . $ kj/::maxcxx . . $ kj/max(97a3da08354c71ff).(boundedValuecxx . . $ kj/`$anonymous_namespace_src/kj/units-test.c++`/boundedValue(13148ffb1ffed4b9).<5,t1cxx . . $ kj/`$anonymous_namespace_src/kj/units-test.c++`/TestCase318#run(49f6e7a06ebc5aa8).t1#>(2), boundedValuecxx . . $ kj/`$anonymous_namespace_src/kj/units-test.c++`/boundedValue(13148ffb1ffed4b9).<4,t2cxx . . $ kj/`$anonymous_namespace_src/kj/units-test.c++`/TestCase318#run(49f6e7a06ebc5aa8).t2#>(3))); |
| 332 | assertTypeAndValuecxx . . $ kj/`$anonymous_namespace_src/kj/units-test.c++`/assertTypeAndValue(249673c20e2b8d5).(boundedValuecxx . . $ kj/`$anonymous_namespace_src/kj/units-test.c++`/boundedValue(13148ffb1ffed4b9).<4,t2cxx . . $ kj/`$anonymous_namespace_src/kj/units-test.c++`/TestCase318#run(49f6e7a06ebc5aa8).t2#>(3), kjcxx . . $ kj/::maxcxx . . $ kj/max(97a3da08354c71ff).(boundedValuecxx . . $ kj/`$anonymous_namespace_src/kj/units-test.c++`/boundedValue(13148ffb1ffed4b9).<4,t2cxx . . $ kj/`$anonymous_namespace_src/kj/units-test.c++`/TestCase318#run(49f6e7a06ebc5aa8).t2#>(3), boundedValuecxx . . $ kj/`$anonymous_namespace_src/kj/units-test.c++`/boundedValue(13148ffb1ffed4b9).<4,t2cxx . . $ kj/`$anonymous_namespace_src/kj/units-test.c++`/TestCase318#run(49f6e7a06ebc5aa8).t2#>(3))); |
| 333 | |
| 334 | assertTypeAndValuecxx . . $ kj/`$anonymous_namespace_src/kj/units-test.c++`/assertTypeAndValue(249673c20e2b8d5).(boundedValuecxx . . $ kj/`$anonymous_namespace_src/kj/units-test.c++`/boundedValue(13148ffb1ffed4b9).<4,t2cxx . . $ kj/`$anonymous_namespace_src/kj/units-test.c++`/TestCase318#run(49f6e7a06ebc5aa8).t2#>(2), kjcxx . . $ kj/::mincxx . . $ kj/min(f74d891f75ea3cc3).(boundedValuecxx . . $ kj/`$anonymous_namespace_src/kj/units-test.c++`/boundedValue(13148ffb1ffed4b9).<4,t2cxx . . $ kj/`$anonymous_namespace_src/kj/units-test.c++`/TestCase318#run(49f6e7a06ebc5aa8).t2#>(3), boundedValuecxx . . $ kj/`$anonymous_namespace_src/kj/units-test.c++`/boundedValue(13148ffb1ffed4b9).<5,t1cxx . . $ kj/`$anonymous_namespace_src/kj/units-test.c++`/TestCase318#run(49f6e7a06ebc5aa8).t1#>(2))); |
| 335 | assertTypeAndValuecxx . . $ kj/`$anonymous_namespace_src/kj/units-test.c++`/assertTypeAndValue(249673c20e2b8d5).(boundedValuecxx . . $ kj/`$anonymous_namespace_src/kj/units-test.c++`/boundedValue(13148ffb1ffed4b9).<4,t2cxx . . $ kj/`$anonymous_namespace_src/kj/units-test.c++`/TestCase318#run(49f6e7a06ebc5aa8).t2#>(2), kjcxx . . $ kj/::mincxx . . $ kj/min(f74d891f75ea3cc3).(boundedValuecxx . . $ kj/`$anonymous_namespace_src/kj/units-test.c++`/boundedValue(13148ffb1ffed4b9).<5,t1cxx . . $ kj/`$anonymous_namespace_src/kj/units-test.c++`/TestCase318#run(49f6e7a06ebc5aa8).t1#>(2), boundedValuecxx . . $ kj/`$anonymous_namespace_src/kj/units-test.c++`/boundedValue(13148ffb1ffed4b9).<4,t2cxx . . $ kj/`$anonymous_namespace_src/kj/units-test.c++`/TestCase318#run(49f6e7a06ebc5aa8).t2#>(3))); |
| 336 | assertTypeAndValuecxx . . $ kj/`$anonymous_namespace_src/kj/units-test.c++`/assertTypeAndValue(249673c20e2b8d5).(boundedValuecxx . . $ kj/`$anonymous_namespace_src/kj/units-test.c++`/boundedValue(13148ffb1ffed4b9).<4,t2cxx . . $ kj/`$anonymous_namespace_src/kj/units-test.c++`/TestCase318#run(49f6e7a06ebc5aa8).t2#>(3), kjcxx . . $ kj/::mincxx . . $ kj/min(f74d891f75ea3cc3).(boundedValuecxx . . $ kj/`$anonymous_namespace_src/kj/units-test.c++`/boundedValue(13148ffb1ffed4b9).<4,t2cxx . . $ kj/`$anonymous_namespace_src/kj/units-test.c++`/TestCase318#run(49f6e7a06ebc5aa8).t2#>(3), boundedValuecxx . . $ kj/`$anonymous_namespace_src/kj/units-test.c++`/boundedValue(13148ffb1ffed4b9).<4,t2cxx . . $ kj/`$anonymous_namespace_src/kj/units-test.c++`/TestCase318#run(49f6e7a06ebc5aa8).t2#>(3))); |
| 337 | |
| 338 | assertTypeAndValuecxx . . $ kj/`$anonymous_namespace_src/kj/units-test.c++`/assertTypeAndValue(249673c20e2b8d5).(boundedValuecxx . . $ kj/`$anonymous_namespace_src/kj/units-test.c++`/boundedValue(13148ffb1ffed4b9).<5,t1cxx . . $ kj/`$anonymous_namespace_src/kj/units-test.c++`/TestCase318#run(49f6e7a06ebc5aa8).t1#>(4), kjcxx . . $ kj/::maxcxx . . $ kj/max(37181cb165709c74).(boundedcxx . . $ kj/bounded(a028f20150fac02e).<4>(), boundedValuecxx . . $ kj/`$anonymous_namespace_src/kj/units-test.c++`/boundedValue(13148ffb1ffed4b9).<5,t1cxx . . $ kj/`$anonymous_namespace_src/kj/units-test.c++`/TestCase318#run(49f6e7a06ebc5aa8).t1#>(2))); |
| 339 | assertTypeAndValuecxx . . $ kj/`$anonymous_namespace_src/kj/units-test.c++`/assertTypeAndValue(249673c20e2b8d5).(boundedValuecxx . . $ kj/`$anonymous_namespace_src/kj/units-test.c++`/boundedValue(13148ffb1ffed4b9).<5,t1cxx . . $ kj/`$anonymous_namespace_src/kj/units-test.c++`/TestCase318#run(49f6e7a06ebc5aa8).t1#>(4), kjcxx . . $ kj/::maxcxx . . $ kj/max(ae1b896721f5b250).(boundedValuecxx . . $ kj/`$anonymous_namespace_src/kj/units-test.c++`/boundedValue(13148ffb1ffed4b9).<5,t1cxx . . $ kj/`$anonymous_namespace_src/kj/units-test.c++`/TestCase318#run(49f6e7a06ebc5aa8).t1#>(2), boundedcxx . . $ kj/bounded(a028f20150fac02e).<4>())); |
| 340 | |
| 341 | assertTypeAndValuecxx . . $ kj/`$anonymous_namespace_src/kj/units-test.c++`/assertTypeAndValue(249673c20e2b8d5).(boundedValuecxx . . $ kj/`$anonymous_namespace_src/kj/units-test.c++`/boundedValue(13148ffb1ffed4b9).<4,t1cxx . . $ kj/`$anonymous_namespace_src/kj/units-test.c++`/TestCase318#run(49f6e7a06ebc5aa8).t1#>(2), kjcxx . . $ kj/::mincxx . . $ kj/min(53dea0cbffdb228b).(boundedcxx . . $ kj/bounded(a028f20150fac02e).<4>(), boundedValuecxx . . $ kj/`$anonymous_namespace_src/kj/units-test.c++`/boundedValue(13148ffb1ffed4b9).<5,t1cxx . . $ kj/`$anonymous_namespace_src/kj/units-test.c++`/TestCase318#run(49f6e7a06ebc5aa8).t1#>(2))); |
| 342 | assertTypeAndValuecxx . . $ kj/`$anonymous_namespace_src/kj/units-test.c++`/assertTypeAndValue(249673c20e2b8d5).(boundedValuecxx . . $ kj/`$anonymous_namespace_src/kj/units-test.c++`/boundedValue(13148ffb1ffed4b9).<4,t1cxx . . $ kj/`$anonymous_namespace_src/kj/units-test.c++`/TestCase318#run(49f6e7a06ebc5aa8).t1#>(2), kjcxx . . $ kj/::mincxx . . $ kj/min(fedd4d8474e0fb55).(boundedValuecxx . . $ kj/`$anonymous_namespace_src/kj/units-test.c++`/boundedValue(13148ffb1ffed4b9).<5,t1cxx . . $ kj/`$anonymous_namespace_src/kj/units-test.c++`/TestCase318#run(49f6e7a06ebc5aa8).t1#>(2), boundedcxx . . $ kj/bounded(a028f20150fac02e).<4>())); |
| 343 | |
| 344 | // These two are degenerate cases. Currently they fail to compile but maybe they shouldn't? |
| 345 | // assertTypeAndValue(bounded<5>(), kj::max(boundedValue<4,t2>(3), bounded<5>())); |
| 346 | // assertTypeAndValue(bounded<5>(), kj::max(bounded<5>(), boundedValue<4,t2>(3))); |
| 347 | |
| 348 | assertTypeAndValuecxx . . $ kj/`$anonymous_namespace_src/kj/units-test.c++`/assertTypeAndValue(249673c20e2b8d5).(boundedValuecxx . . $ kj/`$anonymous_namespace_src/kj/units-test.c++`/boundedValue(13148ffb1ffed4b9).<4,t2cxx . . $ kj/`$anonymous_namespace_src/kj/units-test.c++`/TestCase318#run(49f6e7a06ebc5aa8).t2#>(3), kjcxx . . $ kj/::mincxx . . $ kj/min(fedd4d8474e0fb55).(boundedValuecxx . . $ kj/`$anonymous_namespace_src/kj/units-test.c++`/boundedValue(13148ffb1ffed4b9).<4,t2cxx . . $ kj/`$anonymous_namespace_src/kj/units-test.c++`/TestCase318#run(49f6e7a06ebc5aa8).t2#>(3), boundedcxx . . $ kj/bounded(a028f20150fac02e).<5>())); |
| 349 | assertTypeAndValuecxx . . $ kj/`$anonymous_namespace_src/kj/units-test.c++`/assertTypeAndValue(249673c20e2b8d5).(boundedValuecxx . . $ kj/`$anonymous_namespace_src/kj/units-test.c++`/boundedValue(13148ffb1ffed4b9).<4,t2cxx . . $ kj/`$anonymous_namespace_src/kj/units-test.c++`/TestCase318#run(49f6e7a06ebc5aa8).t2#>(3), kjcxx . . $ kj/::mincxx . . $ kj/min(53dea0cbffdb228b).(boundedcxx . . $ kj/bounded(a028f20150fac02e).<5>(), boundedValuecxx . . $ kj/`$anonymous_namespace_src/kj/units-test.c++`/boundedValue(13148ffb1ffed4b9).<4,t2cxx . . $ kj/`$anonymous_namespace_src/kj/units-test.c++`/TestCase318#run(49f6e7a06ebc5aa8).t2#>(3))); |
| 350 | } |
| 351 | |
| 352 | #if !_MSC_VER // MSVC barfs on this test and I just don't have time to care. |
| 353 | KJ_TESTcxx . . $ `src/kj/test.h:72:9`!("compare bounded quantities of different bounds") { |
| 354 | auto foo = boundedValuecxx . . $ kj/`$anonymous_namespace_src/kj/units-test.c++`/boundedValue(13148ffb1ffed4b9).<12345, uintcxx . . $ kj/uint#>(123) *cxx . . $ kj/`operator*`(42218075a680923e). unitcxx . . $ kj/unit(e3526cbfe7ff9a24).<Quantitycxx . . $ kj/Quantity#<BoundedConstcxx . . $ kj/BoundedConst#<1>, bytecxx . . $ kj/byte#>>(); |
| 355 | auto bar = boundedValuecxx . . $ kj/`$anonymous_namespace_src/kj/units-test.c++`/boundedValue(13148ffb1ffed4b9).<54321, uintcxx . . $ kj/uint#>(123) *cxx . . $ kj/`operator*`(42218075a680923e). unitcxx . . $ kj/unit(e3526cbfe7ff9a24).<Quantitycxx . . $ kj/Quantity#<BoundedConstcxx . . $ kj/BoundedConst#<1>, bytecxx . . $ kj/byte#>>(); |
| 356 | auto baz = boundedcxx . . $ kj/bounded(a028f20150fac02e).<123>() *cxx . . $ kj/`operator*`(42218075a680923e). unitcxx . . $ kj/unit(e3526cbfe7ff9a24).<Quantitycxx . . $ kj/Quantity#<BoundedConstcxx . . $ kj/BoundedConst#<1>, bytecxx . . $ kj/byte#>>(); |
| 357 | |
| 358 | KJ_EXPECTcxx . . $ `src/kj/test.h:92:9`!(foo == foo); |
| 359 | KJ_EXPECTcxx . . $ `src/kj/test.h:92:9`!(foo == bar); |
| 360 | KJ_EXPECTcxx . . $ `src/kj/test.h:92:9`!(foo == baz); |
| 361 | KJ_EXPECTcxx . . $ `src/kj/test.h:92:9`!(bar == foo); |
| 362 | KJ_EXPECTcxx . . $ `src/kj/test.h:92:9`!(bar == bar); |
| 363 | KJ_EXPECTcxx . . $ `src/kj/test.h:92:9`!(bar == baz); |
| 364 | KJ_EXPECTcxx . . $ `src/kj/test.h:92:9`!(baz == foo); |
| 365 | KJ_EXPECTcxx . . $ `src/kj/test.h:92:9`!(baz == bar); |
| 366 | KJ_EXPECTcxx . . $ `src/kj/test.h:92:9`!(baz == baz); |
| 367 | |
| 368 | auto denom = unitcxx . . $ kj/unit(e3526cbfe7ff9a24).<Quantitycxx . . $ kj/Quantity#<BoundedConstcxx . . $ kj/BoundedConst#<1>, int>>(); |
| 369 | |
| 370 | KJ_EXPECTcxx . . $ `src/kj/test.h:92:9`!(foo / denom == foo / denom); |
| 371 | KJ_EXPECTcxx . . $ `src/kj/test.h:92:9`!(foo / denom == bar / denom); |
| 372 | KJ_EXPECTcxx . . $ `src/kj/test.h:92:9`!(foo / denom == baz / denom); |
| 373 | KJ_EXPECTcxx . . $ `src/kj/test.h:92:9`!(bar / denom == foo / denom); |
| 374 | KJ_EXPECTcxx . . $ `src/kj/test.h:92:9`!(bar / denom == bar / denom); |
| 375 | KJ_EXPECTcxx . . $ `src/kj/test.h:92:9`!(bar / denom == baz / denom); |
| 376 | KJ_EXPECTcxx . . $ `src/kj/test.h:92:9`!(baz / denom == foo / denom); |
| 377 | KJ_EXPECTcxx . . $ `src/kj/test.h:92:9`!(baz / denom == bar / denom); |
| 378 | KJ_EXPECTcxx . . $ `src/kj/test.h:92:9`!(baz / denom == baz / denom); |
| 379 | } |
| 380 | #endif |
| 381 | |
| 382 | } // namespace |
| 383 | } // namespace kj |