diff options
Diffstat (limited to 'modules/core/tests')
| -rw-r--r-- | modules/core/tests/abstract_data.cpp | 390 | ||||
| -rw-r--r-- | modules/core/tests/abstract_foundation.cpp | 189 | ||||
| -rw-r--r-- | modules/core/tests/abstract_json.cpp | 326 | ||||
| -rw-r--r-- | modules/core/tests/chunk.cpp | 4 | ||||
| -rw-r--r-- | modules/core/tests/converter.cpp | 2 | ||||
| -rw-r--r-- | modules/core/tests/equilibrium.cpp | 8 | ||||
| -rw-r--r-- | modules/core/tests/flatten.cpp | 8 | ||||
| -rw-r--r-- | modules/core/tests/iterator.cpp | 30 | ||||
| -rw-r--r-- | modules/core/tests/math.cpp | 12 | ||||
| -rw-r--r-- | modules/core/tests/memory.cpp | 2 | ||||
| -rw-r--r-- | modules/core/tests/particles.cpp | 40 | ||||
| -rw-r--r-- | modules/core/tests/vtk_write.cpp | 4 |
12 files changed, 960 insertions, 55 deletions
diff --git a/modules/core/tests/abstract_data.cpp b/modules/core/tests/abstract_data.cpp new file mode 100644 index 0000000..1ee3d62 --- /dev/null +++ b/modules/core/tests/abstract_data.cpp @@ -0,0 +1,390 @@ +#include <forstio/test/suite.hpp> + +#include "../c++/abstract/data.hpp" +#include "../c++/abstract/data_math.hpp" +#include "../c++/abstract/iterator.hpp" +#include "../c++/abstract/math.hpp" + +namespace { +namespace ts { +using namespace kel::lbm::sch; +} + +using kel::lbm::data; +using kel::lbm::enc::Native; + +SAW_TEST("Abstract/Data/Primitive"){ + data<ts::UInt64> a{4u}; + data<ts::UInt64> b{6u}; + + SAW_EXPECT(a.get() == 4u, "value round trips"); + SAW_EXPECT((a + b).get() == 10u, "addition"); + SAW_EXPECT((b - a).get() == 2u, "subtraction"); + SAW_EXPECT((a * b).get() == 24u, "multiplication"); + SAW_EXPECT((b / a).get() == 1u, "integer division"); + + a += b; + SAW_EXPECT(a.get() == 10u, "compound addition mutates"); + a -= b; + SAW_EXPECT(a.get() == 4u, "compound subtraction mutates"); + + SAW_EXPECT(a < b, "ordering"); + SAW_EXPECT(b > a, "reverse ordering"); + SAW_EXPECT(a != b, "inequality"); + SAW_EXPECT(a.equals(data<ts::UInt64>{4u}), "equality"); + + ++a; + SAW_EXPECT(a.get() == 5u, "increment"); +} + +SAW_TEST("Abstract/Data/PrimitiveCast"){ + data<ts::Float64> d{2.75}; + auto as_int = d.cast_to<ts::Int32>(); + SAW_EXPECT(as_int.get() == 2, "float to int truncates"); + + data<ts::UInt8> small{255u}; + auto wide = small.cast_to<ts::UInt64>(); + SAW_EXPECT(wide.get() == 255u, "widening preserves the value"); +} + +SAW_TEST("Abstract/Data/Bool"){ + data<ts::Bool> t{true}; + data<ts::Bool> f{false}; + + SAW_EXPECT(t.get(), "true round trips"); + SAW_EXPECT((!t).get() == false, "negation"); + SAW_EXPECT((t && f).get() == false, "conjunction"); + SAW_EXPECT((t || f).get() == true, "disjunction"); + SAW_EXPECT(t != f, "inequality"); +} + +SAW_TEST("Abstract/Data/MixedPrecision"){ + // Stored as float, read as double. + using TMixed = ts::MixedPrecision<ts::Float32, ts::Float64>; + + data<TMixed> v{1.5}; + SAW_EXPECT(v.get() == 1.5, "a value exactly representable in float survives"); + + data<TMixed> w{2.5}; + SAW_EXPECT((v + w).get() == 4.0, "arithmetic happens at interface precision"); + + static_assert(std::is_same_v<decltype(v.get()), double>, + "reads come back as the interface type"); +} + +SAW_TEST("Abstract/Data/FixedArrayRankOne"){ + data<ts::FixedArray<ts::UInt64,3u>> arr{1u,2u,3u}; + + SAW_EXPECT(arr.at({0u}).get() == 1u, "single index access"); + SAW_EXPECT(arr.at({2u}).get() == 3u, "last element"); + SAW_EXPECT(arr.at({{1u}}).get() == 2u, "index array access"); + SAW_EXPECT(arr.flat_at(1u).get() == 2u, "flat access"); + + arr.at({1u}).set(9u); + SAW_EXPECT(arr.at({1u}).get() == 9u, "writes through"); + + SAW_EXPECT(arr.size().get() == 3u, "size"); + SAW_EXPECT(decltype(arr)::get_dim_size<0u>() == 3u, "compile time extent"); +} + +SAW_TEST("Abstract/Data/FixedArrayRankTwo"){ + data<ts::FixedArray<ts::UInt64,2u,3u>> arr; + + SAW_EXPECT(arr.size().get() == 6u, "flat size is the product of extents"); + + // Row major: index {i,j} sits at i + j*2. + arr.at({{1u,2u}}).set(7u); + SAW_EXPECT(arr.at({{1u,2u}}).get() == 7u, "two dimensional access"); + SAW_EXPECT(arr.flat_at(1u + 2u*2u).get() == 7u, "and its flat position"); + + SAW_EXPECT(decltype(arr)::get_dim_size<0u>() == 2u, "first extent"); + SAW_EXPECT(decltype(arr)::get_dim_size<1u>() == 3u, "second extent"); +} + +SAW_TEST("Abstract/Data/FixedArrayRankZero"){ + // The empty product is one, so a rank zero shape still holds one element. + data<ts::FixedArray<ts::Float64>> scalar_like; + SAW_EXPECT(scalar_like.size().get() == 1u, "rank zero holds exactly one element"); + + scalar_like.at({}).set(3.5); + SAW_EXPECT(scalar_like.at({}).get() == 3.5, "addressed with an empty index"); +} + +SAW_TEST("Abstract/Data/Array"){ + // Extents are runtime, so they come in as the metadata. + data<ts::Array<ts::UInt64,1u>> arr{data<ts::FixedArray<ts::UInt64,1u>>{{3u}}}; + + SAW_EXPECT(arr.size().get() == 3u, "sized from its metadata"); + SAW_EXPECT(arr.get_dim_size(0u) == 3u, "extent is readable"); + + arr.at({1u}).set(5u); + SAW_EXPECT(arr.at({1u}).get() == 5u, "single index access"); + SAW_EXPECT(arr.at({{1u}}).get() == 5u, "index array access"); + + auto eov = arr.add(data<ts::UInt64>{8u}); + SAW_EXPECT(eov.is_value(), "appending to the last dimension works"); + SAW_EXPECT(arr.size().get() == 4u, "and grows it"); + SAW_EXPECT(arr.at({3u}).get() == 8u, "appended value lands last"); +} + +SAW_TEST("Abstract/Data/ArrayFromIntegralExtents"){ + data<ts::Array<ts::UInt64,2u>> arr{2u, 3u}; + + SAW_EXPECT(arr.size().get() == 6u, "extents multiply out"); + arr.at({{1u,2u}}).set(4u); + SAW_EXPECT(arr.at({{1u,2u}}).get() == 4u, "two dimensional access"); +} + +SAW_TEST("Abstract/Data/String"){ + data<ts::String> s{std::string{"hello"}}; + + SAW_EXPECT(s.size().get() == 5u, "length"); + SAW_EXPECT(s.get_at({1u}) == 'e', "indexed read"); + + s.set_at({0u}, 'H'); + SAW_EXPECT(s.stl_view() == std::string_view{"Hello"}, "indexed write"); + + // A String is described by its length, so building one from metadata + // gives a string of that length. + data<ts::String> sized{data<ts::UInt64>{3u}}; + SAW_EXPECT(sized.size().get() == 3u, "sized from its metadata"); +} + +SAW_TEST("Abstract/Data/Tuple"){ + data<ts::Tuple<ts::UInt64, ts::Bool>> t; + + t.get<0u>().set(7u); + t.get<1u>().set(true); + + SAW_EXPECT(t.get<0u>().get() == 7u, "first member"); + SAW_EXPECT(t.get<1u>().get() == true, "second member"); + SAW_EXPECT(decltype(t)::size() == 2u, "member count"); +} + +SAW_TEST("Abstract/Data/Struct"){ + using TStruct = ts::Struct< + ts::Member<ts::UInt64,"count">, + ts::Member<ts::Float64,"weight"> + >; + + data<TStruct> s; + s.get<"count">().set(12u); + s.get<"weight">().set(0.25); + + SAW_EXPECT(s.get<"count">().get() == 12u, "member by name"); + SAW_EXPECT(s.get<"weight">().get() == 0.25, "second member by name"); + SAW_EXPECT(s.get_at_index<0u>().get() == 12u, "and by position"); + SAW_EXPECT(decltype(s)::size().get() == 2u, "member count"); +} + +SAW_TEST("Abstract/Data/Union"){ + using TUnion = ts::Union< + ts::Member<ts::UInt64,"number">, + ts::Member<ts::Bool,"flag"> + >; + + data<TUnion> u; + u.init<"number">().set(3u); + + SAW_EXPECT(u.holds_alternative<"number">(), "holds the initialised member"); + SAW_EXPECT(!u.holds_alternative<"flag">(), "and not the other one"); + SAW_EXPECT(u.get<"number">().get() == 3u, "value reads back"); + + u.init<"flag">().set(true); + SAW_EXPECT(u.holds_alternative<"flag">(), "switching alternative"); + SAW_EXPECT(u.get<"flag">().get() == true, "new value reads back"); +} + +SAW_TEST("Abstract/Data/Tensor"){ + data<ts::Vector<ts::Float64,3u>> a{1.0, 2.0, 3.0}; + data<ts::Vector<ts::Float64,3u>> b{4.0, 5.0, 6.0}; + + SAW_EXPECT(a.at({{0u}}).get() == 1.0, "component access"); + SAW_EXPECT(a.flat_at(2u).get() == 3.0, "flat access"); + + auto sum = a + b; + SAW_EXPECT(sum.flat_at(0u).get() == 5.0, "componentwise addition"); + SAW_EXPECT(sum.flat_at(2u).get() == 9.0, "componentwise addition, last"); + + auto diff = b - a; + SAW_EXPECT(diff.flat_at(1u).get() == 3.0, "componentwise subtraction"); + + auto neg = -a; + SAW_EXPECT(neg.flat_at(0u).get() == -1.0, "negation"); +} + +SAW_TEST("Abstract/Data/TensorScalarOps"){ + data<ts::Vector<ts::Float64,2u>> v{3.0, 4.0}; + auto two = kel::lbm::math::make_scalar<ts::Float64>(2.0); + + auto scaled = v * two; + SAW_EXPECT(scaled.flat_at(0u).get() == 6.0, "scalar multiply"); + + auto halved = v / two; + SAW_EXPECT(halved.flat_at(1u).get() == 2.0, "scalar divide"); +} + +SAW_TEST("Abstract/Data/ScalarTensor"){ + // Rank zero: one element, addressed with an empty index. + data<ts::Scalar<ts::Float64>> s{data<ts::Float64>{2.5}}; + + SAW_EXPECT(s.at({}).get() == 2.5, "empty index access"); + SAW_EXPECT(s.flat_at(0u).get() == 2.5, "flat access"); + SAW_EXPECT(decltype(s)::size().get() == 1u, "holds one element"); +} + +SAW_TEST("Abstract/Math/DotAndNorm"){ + using namespace kel::lbm; + + auto a = math::make_vector<ts::Float64>(3.0, 4.0); + auto b = math::make_vector<ts::Float64>(1.0, 0.0); + + auto d = math::dot<ts::Float64,2u>(a, b); + SAW_EXPECT(d.flat_at(0u).get() == 3.0, "dot product"); + + auto n = math::norm<ts::Float64,2u>(a); + SAW_EXPECT(n.flat_at(0u).get() == 5.0, "3-4-5 triangle"); +} + +SAW_TEST("Abstract/Math/Normalize"){ + using namespace kel::lbm; + + auto a = math::make_vector<ts::Float64>(0.0, 2.0); + auto u = math::normalize<ts::Float64,2u>(a); + + SAW_EXPECT(u.flat_at(0u).get() == 0.0, "x component"); + SAW_EXPECT(u.flat_at(1u).get() == 1.0, "y component is unit length"); + + // A zero vector has no direction to preserve, so it comes back unchanged + // rather than dividing by zero. + auto zero = math::make_vector<ts::Float64>(0.0, 0.0); + auto uz = math::normalize<ts::Float64,2u>(zero); + SAW_EXPECT(uz.flat_at(0u).get() == 0.0, "zero vector survives untouched"); +} + +SAW_TEST("Abstract/Math/Cross"){ + using namespace kel::lbm; + + auto x = math::make_vector<ts::Float64>(1.0, 0.0, 0.0); + auto y = math::make_vector<ts::Float64>(0.0, 1.0, 0.0); + + auto z = math::cross<ts::Float64>(x, y); + SAW_EXPECT(z.flat_at(2u).get() == 1.0, "x cross y is z"); + + // In two dimensions only the normal component survives. + auto a = math::make_vector<ts::Float64>(1.0, 0.0); + auto b = math::make_vector<ts::Float64>(0.0, 1.0); + auto s = math::cross<ts::Float64>(a, b); + SAW_EXPECT(s.flat_at(0u).get() == 1.0, "2d cross is a scalar"); +} + +SAW_TEST("Abstract/Math/Vectorize"){ + using namespace kel::lbm; + + data<ts::FixedArray<ts::Float64,3u>> arr{1.0, 2.0, 3.0}; + auto v = math::vectorize_data<ts::Float64,3u>(arr); + + SAW_EXPECT(v.flat_at(0u).get() == 1.0, "first component carried over"); + SAW_EXPECT(v.flat_at(2u).get() == 3.0, "last component carried over"); +} + +SAW_TEST("Abstract/Math/MatrixVectorMultiply"){ + using namespace kel::lbm; + + // Column major by the row-major-index convention used in get_flat_index: + // at({{i,j}}) is element i of column j. + data<ts::Matrix<ts::Float64,2u,2u>> m; + m.at({{0u,0u}}).set(1.0); + m.at({{0u,1u}}).set(2.0); + m.at({{1u,0u}}).set(3.0); + m.at({{1u,1u}}).set(4.0); + + auto v = math::make_vector<ts::Float64>(1.0, 1.0); + auto r = math::multiply<ts::Float64,2u,2u>(m, v); + + SAW_EXPECT(r.flat_at(0u).get() == 3.0, "first row sums to 3"); + SAW_EXPECT(r.flat_at(1u).get() == 7.0, "second row sums to 7"); +} + +SAW_TEST("Abstract/Math/SumAndFill"){ + using namespace kel::lbm; + + data<ts::Vector<ts::Float64,3u>> v; + math::fill<ts::Float64,3u>(v, data<ts::Float64>{2.0}); + + SAW_EXPECT(v.flat_at(1u).get() == 2.0, "fill writes every element"); + + auto s = math::sum<ts::Float64,3u>(v); + SAW_EXPECT(s.flat_at(0u).get() == 6.0, "sum over the tensor"); +} + +SAW_TEST("Abstract/Iterator/RankOne"){ + using namespace kel::lbm; + + uint64_t visits = 0u; + auto eov = rank_iterator<3u>::in_fixed_bounds( + [&](const index_data<1u>& index) -> error_or<void> { + SAW_EXPECT(index.flat_at(0u).get() == visits, "visited in order"); + ++visits; + return make_void(); + }); + + SAW_EXPECT(eov.is_value(), "iteration succeeded"); + SAW_EXPECT(visits == 3u, "visited every position"); +} + +SAW_TEST("Abstract/Iterator/RankTwo"){ + using namespace kel::lbm; + + // This is the case that could not compile against forstio's iterator, + // because it indexed a rank two index array with a bare integer. + uint64_t visits = 0u; + uint64_t last_i = 0u; + uint64_t last_j = 0u; + + auto eov = rank_iterator<2u,3u>::in_fixed_bounds( + [&](const index_data<2u>& index) -> error_or<void> { + last_i = index.flat_at(0u).get(); + last_j = index.flat_at(1u).get(); + ++visits; + return make_void(); + }); + + SAW_EXPECT(eov.is_value(), "iteration succeeded"); + SAW_EXPECT(visits == 6u, "visited every position of a 2x3 shape"); + SAW_EXPECT(last_i == 1u, "finished on the last i"); + SAW_EXPECT(last_j == 2u, "finished on the last j"); +} + +SAW_TEST("Abstract/Iterator/RankZero"){ + using namespace kel::lbm; + + uint64_t visits = 0u; + auto eov = rank_iterator<>::in_fixed_bounds( + [&](const index_data<0u>&) -> error_or<void> { + ++visits; + return make_void(); + }); + + SAW_EXPECT(eov.is_value(), "iteration succeeded"); + SAW_EXPECT(visits == 1u, "rank zero still has one position"); +} + +SAW_TEST("Abstract/Iterator/PropagatesError"){ + using namespace kel::lbm; + + uint64_t visits = 0u; + auto eov = rank_iterator<5u>::in_fixed_bounds( + [&](const index_data<1u>&) -> error_or<void> { + ++visits; + if(visits == 2u){ + return make_error<err::not_found>(); + } + return make_void(); + }); + + SAW_EXPECT(eov.is_error(), "the error reaches the caller"); + SAW_EXPECT(eov.get_error().is_type<err::not_found>(), "and keeps its type"); + SAW_EXPECT(visits == 2u, "iteration stopped at the failure"); +} +} diff --git a/modules/core/tests/abstract_foundation.cpp b/modules/core/tests/abstract_foundation.cpp new file mode 100644 index 0000000..aea967d --- /dev/null +++ b/modules/core/tests/abstract_foundation.cpp @@ -0,0 +1,189 @@ +#include <forstio/test/suite.hpp> + +#include "../c++/abstract/common.hpp" +#include "../c++/abstract/error.hpp" +#include "../c++/abstract/schema.hpp" +#include "../c++/abstract/stringify_schema.hpp" +#include "../c++/abstract/templates.hpp" + +namespace { +namespace ts { +using namespace kel::lbm::sch; +} + +SAW_TEST("Abstract/Templates/CtMultiply"){ + using namespace kel::lbm; + + static_assert(ct_multiply<uint64_t>::value == 1u, "empty pack is the identity"); + static_assert(ct_multiply<uint64_t,3u>::value == 3u, ""); + static_assert(ct_multiply<uint64_t,2u,3u,4u>::value == 24u, ""); +} + +SAW_TEST("Abstract/Templates/ParameterPack"){ + using namespace kel::lbm; + + static_assert(std::is_same_v<parameter_pack_type<0u, int, char, bool>::type, int>, ""); + static_assert(std::is_same_v<parameter_pack_type<2u, int, char, bool>::type, bool>, ""); + + static_assert(parameter_pack_index<char, int, char, bool>::value == 1u, ""); + + static_assert(parameter_pack_value<1u, uint64_t, 7u, 9u, 11u>::value == 9u, ""); +} + +SAW_TEST("Abstract/Templates/KeyPack"){ + using namespace kel::lbm; + + static_assert(parameter_key_pack_index<"b", "a", "b", "c">::value == 1u, ""); + static_assert(parameter_key_pack_type<2u, "a", "b", "c">::literal == string_literal{"c"}, ""); +} + +SAW_TEST("Abstract/Templates/DigitConversion"){ + using namespace kel::lbm; + + static_assert(ct_convert_to_digits<0u,10u>::literal == string_literal{"0"}, ""); + static_assert(ct_convert_to_digits<7u,10u>::literal == string_literal{"7"}, ""); + static_assert(ct_convert_to_digits<1024u,10u>::literal == string_literal{"1024"}, ""); +} + +SAW_TEST("Abstract/StringLiteral/Concat"){ + using namespace kel::lbm; + + static_assert((string_literal{"foo"} + string_literal{"bar"}) == string_literal{"foobar"}, ""); + static_assert(string_literal{"foo"}.view() == std::string_view{"foo"}, ""); +} + +SAW_TEST("Abstract/Schema/Meta"){ + using namespace kel::lbm; + + // Compile time shapes carry nothing at runtime. + static_assert(std::is_same_v<ts::UInt64::Meta, ts::Void>, ""); + static_assert(std::is_same_v<ts::FixedArray<ts::UInt64,3u>::Meta, ts::Void>, ""); + + // A dynamically sized Array is described by its extents. + static_assert(std::is_same_v< + ts::Array<ts::Float64,2u>::Meta, + ts::FixedArray<ts::UInt64,2u>>, ""); + + // A String is described by its length. + static_assert(std::is_same_v<ts::String::Meta, ts::UInt64>, ""); + + // A Tensor is addressed through a rank sized index. + static_assert(std::is_same_v< + ts::Vector<ts::Float64,3u>::Meta, + ts::FixedArray<ts::UInt64,1u>>, ""); + static_assert(std::is_same_v< + ts::Scalar<ts::Float64>::Meta, + ts::FixedArray<ts::UInt64,0u>>, ""); + + // Structural schemas recurse into their members. + using TStruct = ts::Struct< + ts::Member<ts::UInt64,"count">, + ts::Member<ts::Array<ts::Float64,1u>,"values"> + >; + static_assert(std::is_same_v< + TStruct::Meta, + ts::Struct< + ts::Member<ts::Void,"count">, + ts::Member<ts::FixedArray<ts::UInt64,1u>,"values"> + >>, ""); + + static_assert(std::is_same_v< + ts::Tuple<ts::UInt64, ts::String>::Meta, + ts::Tuple<ts::Void, ts::UInt64>>, ""); +} + +SAW_TEST("Abstract/Schema/PrimitiveShape"){ + using namespace kel::lbm; + + static_assert(ts::UInt64::Bytes == 8u, ""); + static_assert(std::is_same_v<ts::UInt64::Kind, ts::UnsignedInteger>, ""); + static_assert(std::is_same_v<ts::UInt64::StorageType, ts::UInt64>, ""); + static_assert(std::is_same_v<ts::UInt64::InterfaceType, ts::UInt64>, ""); + + using TMixed = ts::MixedPrecision<ts::Float32, ts::Float64>; + static_assert(std::is_same_v<TMixed::StorageType, ts::Float32>, ""); + static_assert(std::is_same_v<TMixed::InterfaceType, ts::Float64>, ""); + + static_assert(ts::FixedArray<ts::UInt64,2u,3u>::FlatSize == 6u, ""); + static_assert(ts::FixedArray<ts::UInt64,2u,3u>::Rank == 2u, ""); + static_assert(ts::Scalar<ts::Float64>::FlatSize == 1u, "rank zero holds one element"); +} + +SAW_TEST("Abstract/SchemaStringify/Primitive"){ + using namespace kel::lbm; + + static_assert(schema_to_string<ts::UInt64>::literal + == string_literal{"Primitive<UnsignedInteger,8>"}, ""); + static_assert(schema_to_string<ts::Float32>::literal + == string_literal{"Primitive<FloatingPoint,4>"}, ""); +} + +SAW_TEST("Abstract/SchemaStringify/Composite"){ + using namespace kel::lbm; + + static_assert(schema_to_string<ts::FixedArray<ts::UInt8,2u,3u>>::literal + == string_literal{"FixedArray<Primitive<UnsignedInteger,1>,2,3>"}, ""); + + static_assert(schema_to_string<ts::Tuple<ts::Bool, ts::String>>::literal + == string_literal{"Tuple<Bool,String>"}, ""); +} + +SAW_TEST("Abstract/Error/MakeError"){ + using namespace kel::lbm; + + auto err = make_error<err::not_found>("missing thing"); + SAW_EXPECT(err.failed(), "a not_found is an error"); + SAW_EXPECT(err.is_recoverable(), "not_found is recoverable"); + SAW_EXPECT(err.is_type<err::not_found>(), "error keeps its type"); + SAW_EXPECT(!err.is_type<err::out_of_memory>(), "and is distinguishable"); + SAW_EXPECT(err.get_message() == std::string_view{"missing thing"}, "message survives"); +} + +SAW_TEST("Abstract/Error/Critical"){ + using namespace kel::lbm; + + auto err = make_error<err::out_of_memory>(); + SAW_EXPECT(err.is_critical(), "out_of_memory is critical"); + SAW_EXPECT(!err.is_recoverable(), "and therefore not recoverable"); +} + +SAW_TEST("Abstract/Error/ErrorOr"){ + using namespace kel::lbm; + + error_or<uint64_t> good{uint64_t{42u}}; + SAW_EXPECT(good.is_value(), "holds a value"); + SAW_EXPECT(!good.is_error(), "and not an error"); + SAW_EXPECT(good.get_value() == 42u, "value round trips"); + + error_or<uint64_t> bad{make_error<err::not_found>()}; + SAW_EXPECT(bad.is_error(), "holds an error"); + SAW_EXPECT(!bad.is_value(), "and not a value"); + SAW_EXPECT(bad.get_error().is_type<err::not_found>(), "error type survives"); +} + +SAW_TEST("Abstract/Error/VoidPath"){ + using namespace kel::lbm; + + error_or<void> ok{make_void()}; + SAW_EXPECT(ok.is_value(), "make_void is a value, not an error"); +} + +SAW_TEST("Abstract/Common/Pointers"){ + using namespace kel::lbm; + + auto owned = heap<uint64_t>(7u); + SAW_EXPECT(*owned == 7u, "heap constructs in place"); + + ptr<uint64_t> empty; + SAW_EXPECT(!empty.is_valid(), "a default ptr is empty"); + + uint64_t backing = 3u; + ptr<uint64_t> filled{backing}; + SAW_EXPECT(filled.is_valid(), "a bound ptr is valid"); + SAW_EXPECT(filled() == 3u, "and reads through"); + + ref<uint64_t> r{backing}; + r() = 9u; + SAW_EXPECT(backing == 9u, "ref writes through to its referent"); +} +} diff --git a/modules/core/tests/abstract_json.cpp b/modules/core/tests/abstract_json.cpp new file mode 100644 index 0000000..9592158 --- /dev/null +++ b/modules/core/tests/abstract_json.cpp @@ -0,0 +1,326 @@ +#include <forstio/test/suite.hpp> + +#include "../c++/abstract/json.hpp" + +namespace { +namespace ts { +using namespace kel::lbm::sch; +} + +using kel::lbm::codec; +using kel::lbm::data; +using kel::lbm::enc::Json; +using kel::lbm::enc::Native; + +template<typename Schema> +std::string encode_to_string(const data<Schema>& value, bool pretty = false){ + data<Schema, Json> out; + codec<Schema, Json> c; + c.set_pretty(pretty); + auto eov = c.encode(value, out); + SAW_EXPECT(eov.is_value(), "encoding succeeded"); + return out.stl_string(); +} + +SAW_TEST("Abstract/Json/EncodePrimitives"){ + SAW_EXPECT(encode_to_string(data<ts::UInt64>{42u}) == "42", "unsigned"); + SAW_EXPECT(encode_to_string(data<ts::Int32>{-7}) == "-7", "signed"); + SAW_EXPECT(encode_to_string(data<ts::Bool>{true}) == "true", "bool true"); + SAW_EXPECT(encode_to_string(data<ts::Bool>{false}) == "false", "bool false"); +} + +SAW_TEST("Abstract/Json/EncodeString"){ + data<ts::String> s{std::string{"a\"b\\c\nd"}}; + // Quote, backslash and newline all have to come back escaped. + SAW_EXPECT(encode_to_string(s) == "\"a\\\"b\\\\c\\nd\"", "escapes applied"); +} + +SAW_TEST("Abstract/Json/DecodePrimitives"){ + data<ts::UInt64> u; + codec<ts::UInt64, Json> cu; + SAW_EXPECT(cu.decode(data<ts::UInt64,Json>{std::string{"123"}}, u).is_value(), "decoded"); + SAW_EXPECT(u.get() == 123u, "unsigned round trips"); + + data<ts::Float64> f; + codec<ts::Float64, Json> cf; + SAW_EXPECT(cf.decode(data<ts::Float64,Json>{std::string{"-0.5e1"}}, f).is_value(), "decoded"); + SAW_EXPECT(f.get() == -5.0, "exponent form is understood"); +} + +SAW_TEST("Abstract/Json/FloatRoundTrip"){ + // max_digits10 precision is what makes this exact rather than approximate. + const double original = 0.1234567890123456789; + data<ts::Float64> in{original}; + + data<ts::Float64> out; + codec<ts::Float64, Json> c; + auto eov = c.decode(data<ts::Float64,Json>{encode_to_string(in)}, out); + SAW_EXPECT(eov.is_value(), "round trip decoded"); + SAW_EXPECT(out.get() == in.get(), "a double survives a save and load cycle"); +} + +SAW_TEST("Abstract/Json/IntegerRejectsFraction"){ + // Truncating 1.5 into an integer field would lose data quietly. + data<ts::UInt64> u; + codec<ts::UInt64, Json> c; + auto eov = c.decode(data<ts::UInt64,Json>{std::string{"1.5"}}, u); + SAW_EXPECT(eov.is_error(), "a fractional value is not an integer"); +} + +SAW_TEST("Abstract/Json/UnsignedRejectsNegative"){ + data<ts::UInt64> u; + codec<ts::UInt64, Json> c; + auto eov = c.decode(data<ts::UInt64,Json>{std::string{"-1"}}, u); + SAW_EXPECT(eov.is_error(), "a negative value is not unsigned"); +} + +SAW_TEST("Abstract/Json/EncodeAndDecodeStruct"){ + using TStruct = ts::Struct< + ts::Member<ts::UInt64,"count">, + ts::Member<ts::Float64,"weight"> + >; + + data<TStruct> in; + in.get<"count">().set(3u); + in.get<"weight">().set(0.5); + + auto text = encode_to_string(in); + SAW_EXPECT(text == "{\"count\":3,\"weight\":0.5}", "object layout"); + + data<TStruct> out; + codec<TStruct, Json> c; + auto eov = c.decode(data<TStruct,Json>{text}, out); + SAW_EXPECT(eov.is_value(), "decoded"); + SAW_EXPECT(out.get<"count">().get() == 3u, "count round trips"); + SAW_EXPECT(out.get<"weight">().get() == 0.5, "weight round trips"); +} + +SAW_TEST("Abstract/Json/StructIgnoresUnknownKeys"){ + using TStruct = ts::Struct<ts::Member<ts::UInt64,"count">>; + + data<TStruct> out; + codec<TStruct, Json> c; + // A nested unknown value has to be skipped whole, not just one token. + auto eov = c.decode( + data<TStruct,Json>{std::string{ + "{\"extra\":{\"a\":[1,2,{\"b\":\"x\"}]},\"count\":9}"}}, + out); + + SAW_EXPECT(eov.is_value(), "unknown members are skipped"); + SAW_EXPECT(out.get<"count">().get() == 9u, "known member still lands"); +} + +SAW_TEST("Abstract/Json/StructMissingMember"){ + using TStruct = ts::Struct< + ts::Member<ts::UInt64,"count">, + ts::Member<ts::UInt64,"other"> + >; + + // Lenient by default: a config states only its deviations. + data<TStruct> lenient; + codec<TStruct, Json> c; + auto eov = c.decode(data<TStruct,Json>{std::string{"{\"count\":1}"}}, lenient); + SAW_EXPECT(eov.is_value(), "a missing member is allowed by default"); + SAW_EXPECT(lenient.get<"other">().get() == 0u, "and keeps its default"); + + data<TStruct> strict; + codec<TStruct, Json> cs; + cs.set_strict(true); + auto eov_s = cs.decode(data<TStruct,Json>{std::string{"{\"count\":1}"}}, strict); + SAW_EXPECT(eov_s.is_error(), "strict decoding demands every member"); +} + +SAW_TEST("Abstract/Json/FixedArray"){ + using TArr = ts::FixedArray<ts::UInt64,3u>; + + data<TArr> in{1u,2u,3u}; + auto text = encode_to_string(in); + SAW_EXPECT(text == "[1,2,3]", "array layout"); + + data<TArr> out; + codec<TArr, Json> c; + SAW_EXPECT(c.decode(data<TArr,Json>{text}, out).is_value(), "decoded"); + SAW_EXPECT(out.flat_at(2u).get() == 3u, "elements round trip"); +} + +SAW_TEST("Abstract/Json/FixedArrayLengthMismatch"){ + using TArr = ts::FixedArray<ts::UInt64,3u>; + data<TArr> out; + + codec<TArr, Json> c_short; + SAW_EXPECT(c_short.decode(data<TArr,Json>{std::string{"[1,2]"}}, out).is_error(), + "too few elements is an error, there is no default to fill with"); + + codec<TArr, Json> c_long; + SAW_EXPECT(c_long.decode(data<TArr,Json>{std::string{"[1,2,3,4]"}}, out).is_error(), + "too many elements is an error, there is nowhere to put them"); +} + +SAW_TEST("Abstract/Json/DynamicArrayGrows"){ + using TArr = ts::Array<ts::UInt64,1u>; + + data<TArr> out; + codec<TArr, Json> c; + SAW_EXPECT(c.decode(data<TArr,Json>{std::string{"[5,6,7,8]"}}, out).is_value(), "decoded"); + SAW_EXPECT(out.size().get() == 4u, "array grew to fit the document"); + SAW_EXPECT(out.at({3u}).get() == 8u, "last element landed"); +} + +SAW_TEST("Abstract/Json/Tuple"){ + using TTup = ts::Tuple<ts::UInt64, ts::Bool>; + + data<TTup> in; + in.get<0u>().set(4u); + in.get<1u>().set(true); + + auto text = encode_to_string(in); + SAW_EXPECT(text == "[4,true]", "tuple is an array"); + + data<TTup> out; + codec<TTup, Json> c; + SAW_EXPECT(c.decode(data<TTup,Json>{text}, out).is_value(), "decoded"); + SAW_EXPECT(out.get<0u>().get() == 4u, "first element"); + SAW_EXPECT(out.get<1u>().get() == true, "second element"); +} + +SAW_TEST("Abstract/Json/Tensor"){ + using TVec = ts::Vector<ts::Float64,3u>; + + data<TVec> in{1.0, 2.0, 3.0}; + auto text = encode_to_string(in); + + data<TVec> out; + codec<TVec, Json> c; + SAW_EXPECT(c.decode(data<TVec,Json>{text}, out).is_value(), "decoded"); + SAW_EXPECT(out.flat_at(1u).get() == 2.0, "components round trip"); +} + +SAW_TEST("Abstract/Json/Nested"){ + using TInner = ts::Struct<ts::Member<ts::UInt64,"n">>; + using TOuter = ts::Struct< + ts::Member<TInner,"inner">, + ts::Member<ts::FixedArray<ts::UInt64,2u>,"pair"> + >; + + data<TOuter> in; + in.get<"inner">().get<"n">().set(1u); + in.get<"pair">().flat_at(0u).set(2u); + in.get<"pair">().flat_at(1u).set(3u); + + auto text = encode_to_string(in); + SAW_EXPECT(text == "{\"inner\":{\"n\":1},\"pair\":[2,3]}", "nested layout"); + + data<TOuter> out; + codec<TOuter, Json> c; + SAW_EXPECT(c.decode(data<TOuter,Json>{text}, out).is_value(), "decoded"); + SAW_EXPECT(out.get<"inner">().get<"n">().get() == 1u, "nested member"); + SAW_EXPECT(out.get<"pair">().flat_at(1u).get() == 3u, "nested array"); +} + +SAW_TEST("Abstract/Json/Whitespace"){ + using TStruct = ts::Struct<ts::Member<ts::UInt64,"count">>; + + data<TStruct> out; + codec<TStruct, Json> c; + auto eov = c.decode( + data<TStruct,Json>{std::string{" {\n\t\"count\" : 5\r\n} "}}, out); + + SAW_EXPECT(eov.is_value(), "whitespace around tokens is ignored"); + SAW_EXPECT(out.get<"count">().get() == 5u, "value still read"); +} + +SAW_TEST("Abstract/Json/RejectsTrailingContent"){ + data<ts::UInt64> out; + codec<ts::UInt64, Json> c; + auto eov = c.decode(data<ts::UInt64,Json>{std::string{"1 2"}}, out); + SAW_EXPECT(eov.is_error(), "content after the value means a malformed document"); +} + +SAW_TEST("Abstract/Json/RejectsMalformed"){ + using TStruct = ts::Struct<ts::Member<ts::UInt64,"count">>; + data<TStruct> out; + + codec<TStruct, Json> c_unclosed; + SAW_EXPECT(c_unclosed.decode(data<TStruct,Json>{std::string{"{\"count\":1"}}, out).is_error(), + "unterminated object"); + + codec<TStruct, Json> c_empty; + SAW_EXPECT(c_empty.decode(data<TStruct,Json>{std::string{""}}, out).is_error(), + "empty input"); + + codec<TStruct, Json> c_garbage; + SAW_EXPECT(c_garbage.decode(data<TStruct,Json>{std::string{"{\"count\":}"}}, out).is_error(), + "missing value"); +} + +SAW_TEST("Abstract/Json/DepthLimit"){ + using TArr = ts::Array<ts::UInt64,1u>; + + // The guard is against pathological nesting in untrusted input; a flat + // document sits well inside it. + data<TArr> out; + kel::lbm::codec_config<Json> cfg; + cfg.depth = 1u; + codec<TArr, Json> c{cfg}; + SAW_EXPECT(c.decode(data<TArr,Json>{std::string{"[1,2]"}}, out).is_value(), + "one level of nesting is within a depth of one"); +} + +SAW_TEST("Abstract/Json/StringEscapeRoundTrip"){ + data<ts::String> in{std::string{"tab\there \"quoted\" back\\slash"}}; + + data<ts::String> out; + codec<ts::String, Json> c; + auto eov = c.decode(data<ts::String,Json>{encode_to_string(in)}, out); + + SAW_EXPECT(eov.is_value(), "decoded"); + SAW_EXPECT(out.stl_view() == in.stl_view(), "escapes survive a round trip"); +} + +SAW_TEST("Abstract/Json/UnicodeEscape"){ + data<ts::String> out; + codec<ts::String, Json> c; + // U+00E9 encodes to two UTF-8 bytes. + auto eov = c.decode(data<ts::String,Json>{std::string{"\"\\u00e9\""}}, out); + + SAW_EXPECT(eov.is_value(), "decoded"); + SAW_EXPECT(out.size().get() == 2u, "decoded to UTF-8 rather than one byte"); +} + +SAW_TEST("Abstract/Json/PrettyPrint"){ + using TStruct = ts::Struct<ts::Member<ts::UInt64,"count">>; + + data<TStruct> in; + in.get<"count">().set(1u); + + auto text = encode_to_string(in, true); + SAW_EXPECT(text == "{\n \"count\": 1\n}", "pretty layout"); + + // Pretty output still has to parse back. + data<TStruct> out; + codec<TStruct, Json> c; + SAW_EXPECT(c.decode(data<TStruct,Json>{text}, out).is_value(), "reparsed"); + SAW_EXPECT(out.get<"count">().get() == 1u, "value preserved"); +} + +SAW_TEST("Abstract/Json/LbmConfigShape"){ + // The shape config.hpp actually loads. + using TConfig = ts::Struct< + ts::Member<ts::Float64, "delta_x">, + ts::Member<ts::Float64, "kinematic_viscosity">, + ts::Member<ts::Float64, "delta_t"> + >; + + data<TConfig> out; + codec<TConfig, Json> c; + auto eov = c.decode( + data<TConfig,Json>{std::string{ + "{\"delta_x\":0.01,\"kinematic_viscosity\":1.5e-5,\"delta_t\":0.001}"}}, + out); + + SAW_EXPECT(eov.is_value(), "a config document decodes"); + SAW_EXPECT(out.get<"delta_x">().get() == 0.01, "delta_x"); + SAW_EXPECT(out.get<"kinematic_viscosity">().get() == 1.5e-5, "viscosity"); + SAW_EXPECT(out.get<"delta_t">().get() == 0.001, "delta_t"); +} +} diff --git a/modules/core/tests/chunk.cpp b/modules/core/tests/chunk.cpp index 008d4c6..72d1341 100644 --- a/modules/core/tests/chunk.cpp +++ b/modules/core/tests/chunk.cpp @@ -4,7 +4,7 @@ namespace { namespace sch { -using namespace saw::schema; +using namespace kel::lbm::sch; } SAW_TEST("Chunk Ghost size 0"){ @@ -39,7 +39,7 @@ SAW_TEST("Chunk 2D setup"){ using TestChunk = lbm::sch::Chunk<sch::Float32, 1u, 2u, 2u>; - auto chunk = saw::heap<saw::data<TestChunk>>(); + auto chunk = kel::lbm::heap<kel::lbm::data<TestChunk>>(); chunk->at({{0u,0u}}).set(1.0f); SAW_EXPECT((chunk->ghost_at({{1u,1u}}).get() == 1.0f),"Check if ghost is at shifted spot."); } diff --git a/modules/core/tests/converter.cpp b/modules/core/tests/converter.cpp index 4fc536f..fa4a46c 100644 --- a/modules/core/tests/converter.cpp +++ b/modules/core/tests/converter.cpp @@ -18,7 +18,7 @@ SAW_TEST("Si Meter to Lbm Meter"){ {0.1} }; - saw::data<sch::SiMeter<sch::T>> si_m{1.0}; + kel::lbm::data<sch::SiMeter<sch::T>> si_m{1.0}; auto lbm_m = converter.meter_si_to_lbm(si_m); SAW_EXPECT(lbm_m.handle().get() == 10.0, "Correct si to lbm conversion"); diff --git a/modules/core/tests/equilibrium.cpp b/modules/core/tests/equilibrium.cpp index 7d36600..ad11699 100644 --- a/modules/core/tests/equilibrium.cpp +++ b/modules/core/tests/equilibrium.cpp @@ -11,15 +11,15 @@ void check_equilibrium(){ using dfi = lbm::df_info<lbm::sch::Float64,Descriptor>; - saw::data<lbm::sch::Scalar<lbm::sch::Float64>> rho; + kel::lbm::data<lbm::sch::Scalar<lbm::sch::Float64>> rho; rho.at({}).set(1.0); - saw::data<lbm::sch::Vector<lbm::sch::Float64,Descriptor::D>> vel; - for(saw::data<lbm::sch::UInt64> i{0u}; i.get() < Descriptor::D; ++i){ + kel::lbm::data<lbm::sch::Vector<lbm::sch::Float64,Descriptor::D>> vel; + for(kel::lbm::data<lbm::sch::UInt64> i{0u}; i.get() < Descriptor::D; ++i){ vel.at({{i}}) = {0.0}; } auto eq = lbm::equilibrium<lbm::sch::Float64,Descriptor>(rho,vel); - for(saw::data<lbm::sch::UInt64> i{0u}; i.get() < Descriptor::Q; ++i){ + for(kel::lbm::data<lbm::sch::UInt64> i{0u}; i.get() < Descriptor::Q; ++i){ SAW_EXPECT(eq.at(i).get() == dfi::weights[i.get()], std::string{"No momentum and normalized rho should be exactly the weights: "} + std::to_string(eq.at(i).get()) + std::string{" "} + std::to_string(dfi::weights[i.get()])); } } diff --git a/modules/core/tests/flatten.cpp b/modules/core/tests/flatten.cpp index 84b3fa4..3da05b5 100644 --- a/modules/core/tests/flatten.cpp +++ b/modules/core/tests/flatten.cpp @@ -4,15 +4,15 @@ namespace { namespace sch { -using namespace saw::schema; +using namespace kel::lbm::sch; } SAW_TEST("Flatten Index Stride"){ using namespace kel; - constexpr saw::data<sch::UInt64> zero = lbm::flatten_index<sch::UInt64,3u>::stride<0u>({{2u,4u,3u}}); - constexpr saw::data<sch::UInt64> one = lbm::flatten_index<sch::UInt64,3u>::stride<1u>({{2u,4u,3u}}); - constexpr saw::data<sch::UInt64> two = lbm::flatten_index<sch::UInt64,3u>::stride<2u>({{2u,4u,3u}}); + constexpr kel::lbm::data<sch::UInt64> zero = lbm::flatten_index<sch::UInt64,3u>::stride<0u>({{2u,4u,3u}}); + constexpr kel::lbm::data<sch::UInt64> one = lbm::flatten_index<sch::UInt64,3u>::stride<1u>({{2u,4u,3u}}); + constexpr kel::lbm::data<sch::UInt64> two = lbm::flatten_index<sch::UInt64,3u>::stride<2u>({{2u,4u,3u}}); SAW_EXPECT(zero.get() == 1u, "Zero is correct"); SAW_EXPECT(one.get() == 2u, "Zero is correct"); diff --git a/modules/core/tests/iterator.cpp b/modules/core/tests/iterator.cpp index 919c12c..4c1f877 100644 --- a/modules/core/tests/iterator.cpp +++ b/modules/core/tests/iterator.cpp @@ -12,10 +12,10 @@ using namespace kel::lbm::sch; SAW_TEST("Old Iterate"){ using namespace kel; - saw::data<sch::FixedArray<sch::UInt64,2u>> start{{0u,0u}}; - saw::data<sch::FixedArray<sch::UInt64,2u>> end{{3u,3u}}; + kel::lbm::data<sch::FixedArray<sch::UInt64,2u>> start{{0u,0u}}; + kel::lbm::data<sch::FixedArray<sch::UInt64,2u>> end{{3u,3u}}; - lbm::iterate_over([](const saw::data<sch::FixedArray<sch::UInt64,2u>>& index){ + lbm::iterate_over([](const kel::lbm::data<sch::FixedArray<sch::UInt64,2u>>& index){ std::cout<<"Index: "<<index.at({0u}).get()<<" "<<index.at({1u}).get()<<std::endl; }, start, end); } @@ -23,7 +23,7 @@ SAW_TEST("Old Iterate"){ SAW_TEST("CT Tuple Iterator"){ using namespace kel; - saw::data< + kel::lbm::data< sch::Tuple< sch::Float32, sch::Int16, @@ -32,18 +32,18 @@ SAW_TEST("CT Tuple Iterator"){ > > tup; - lbm::ct_tuple_iterator<std::decay_t<decltype(tup)>::Schema>::apply([](auto& val) -> saw::error_or<void> { - return saw::make_void(); + lbm::ct_tuple_iterator<std::decay_t<decltype(tup)>::Schema>::apply([](auto& val) -> kel::lbm::error_or<void> { + return kel::lbm::make_void(); },tup); } SAW_TEST("Old Iterate with Distance 1"){ using namespace kel; - saw::data<sch::FixedArray<sch::UInt64,2u>> start{{0u,0u}}; - saw::data<sch::FixedArray<sch::UInt64,2u>> end{{4u,4u}}; + kel::lbm::data<sch::FixedArray<sch::UInt64,2u>> start{{0u,0u}}; + kel::lbm::data<sch::FixedArray<sch::UInt64,2u>> end{{4u,4u}}; - lbm::iterate_over([](const saw::data<sch::FixedArray<sch::UInt64,2u>>& index){ + lbm::iterate_over([](const kel::lbm::data<sch::FixedArray<sch::UInt64,2u>>& index){ std::cout<<"Index: "<<index.at({0u}).get()<<" "<<index.at({1u}).get()<<std::endl; }, start, end, {{1u,1u}}); } @@ -51,10 +51,10 @@ SAW_TEST("Old Iterate with Distance 1"){ SAW_TEST("Iterate - 2D"){ using namespace kel; - saw::data<sch::FixedArray<sch::UInt64,2u>> start{{0u,0u}}; - saw::data<sch::FixedArray<sch::UInt64,2u>> end{{3u,3u}}; + kel::lbm::data<sch::FixedArray<sch::UInt64,2u>> start{{0u,0u}}; + kel::lbm::data<sch::FixedArray<sch::UInt64,2u>> end{{3u,3u}}; - lbm::iterator<2u>::apply([](const saw::data<sch::FixedArray<sch::UInt64,2u>>& index){ + lbm::iterator<2u>::apply([](const kel::lbm::data<sch::FixedArray<sch::UInt64,2u>>& index){ std::cout<<"Index: "<<index.at({0u}).get()<<" "<<index.at({1u}).get()<<std::endl; }, start, end); } @@ -62,10 +62,10 @@ SAW_TEST("Iterate - 2D"){ SAW_TEST("Iterate with Distance 1 - 2D"){ using namespace kel; - saw::data<sch::FixedArray<sch::UInt64,2u>> start{{0u,0u}}; - saw::data<sch::FixedArray<sch::UInt64,2u>> end{{4u,4u}}; + kel::lbm::data<sch::FixedArray<sch::UInt64,2u>> start{{0u,0u}}; + kel::lbm::data<sch::FixedArray<sch::UInt64,2u>> end{{4u,4u}}; - lbm::iterator<2u>::apply([](const saw::data<sch::FixedArray<sch::UInt64,2u>>& index){ + lbm::iterator<2u>::apply([](const kel::lbm::data<sch::FixedArray<sch::UInt64,2u>>& index){ std::cout<<"Index: "<<index.at({0u}).get()<<" "<<index.at({1u}).get()<<std::endl; }, start, end, {{1u,1u}}); } diff --git a/modules/core/tests/math.cpp b/modules/core/tests/math.cpp index d456ce8..3224e40 100644 --- a/modules/core/tests/math.cpp +++ b/modules/core/tests/math.cpp @@ -5,25 +5,25 @@ namespace { namespace sch { -using namespace saw::schema; +using namespace kel::lbm::sch; } SAW_TEST("Math 1-Linear"){ using namespace kel; - saw::data<sch::FixedArray<sch::Vector<sch::Float64,1u>,2u>> field; + kel::lbm::data<sch::FixedArray<sch::Vector<sch::Float64,1u>,2u>> field; { field.at({{0u}}).at({{0u}}).set(-1.0); field.at({{1u}}).at({{0u}}).set(2.0); } - saw::data<sch::Vector<sch::Float64,1u>> pos; + kel::lbm::data<sch::Vector<sch::Float64,1u>> pos; pos.at({{0u}}).set(0.3); } SAW_TEST("Math/Floor Index and Fraction from Position"){ using namespace kel; - saw::data<sch::Vector<sch::Float64,2u>> pos; + kel::lbm::data<sch::Vector<sch::Float64,2u>> pos; { pos.at({{0u}}) = 43.999; @@ -48,14 +48,14 @@ SAW_TEST("Math/Floor Index and Fraction from Position"){ SAW_TEST("Math/Floor Index and Fraction from Position and Bounded"){ using namespace kel; - saw::data<sch::Vector<sch::Float64,2u>> pos; + kel::lbm::data<sch::Vector<sch::Float64,2u>> pos; { pos.at({{0u}}) = 43.999; pos.at({{1u}}) = -50.0; } - saw::data<sch::Vector<sch::UInt64,2U>> bound; + kel::lbm::data<sch::Vector<sch::UInt64,2U>> bound; { bound.at({{0u}}) = 32u; bound.at({{1u}}) = 16u; diff --git a/modules/core/tests/memory.cpp b/modules/core/tests/memory.cpp index d59d212..f0b1499 100644 --- a/modules/core/tests/memory.cpp +++ b/modules/core/tests/memory.cpp @@ -4,7 +4,7 @@ namespace { namespace sch { -using namespace saw::schema; +using namespace kel::lbm::sch; using TStruct = Struct< Member<Float32,"a">, diff --git a/modules/core/tests/particles.cpp b/modules/core/tests/particles.cpp index e060097..823bcd7 100644 --- a/modules/core/tests/particles.cpp +++ b/modules/core/tests/particles.cpp @@ -12,7 +12,7 @@ using T = Float64; SAW_TEST("Verlet step 2D - Planar"){ using namespace kel; - saw::data<sch::Particle<sch::T,2u>> particle; + kel::lbm::data<sch::Particle<sch::T,2u>> particle; auto& body = particle.template get<"rigid_body">(); auto& pos = body.template get<"position">(); auto& pos_old = body.template get<"position_old">(); @@ -22,7 +22,7 @@ SAW_TEST("Verlet step 2D - Planar"){ acc.at({{0}}).set({1.0}); - saw::data<sch::Scalar<sch::T>> dt; + kel::lbm::data<sch::Scalar<sch::T>> dt; dt.at({}).set(0.5); lbm::verlet_step_lambda<sch::T,2u>(particle,dt); @@ -33,7 +33,7 @@ SAW_TEST("Verlet step 2D - Planar"){ SAW_TEST("No Collision Spheroid 2D"){ using namespace kel; - saw::data<sch::Particle<sch::T,2u>> part_a; + kel::lbm::data<sch::Particle<sch::T,2u>> part_a; { auto& body = part_a.template get<"rigid_body">(); auto& pos = body.template get<"position">(); @@ -42,7 +42,7 @@ SAW_TEST("No Collision Spheroid 2D"){ pos.at({{1u}}) = 0.2; } - saw::data<sch::Particle<sch::T,2u>> part_b; + kel::lbm::data<sch::Particle<sch::T,2u>> part_b; { auto& body = part_b.template get<"rigid_body">(); auto& pos = body.template get<"position">(); @@ -59,7 +59,7 @@ SAW_TEST("No Collision Spheroid 2D"){ SAW_TEST("Collision Spheroid 2D"){ using namespace kel; - saw::data<sch::Particle<sch::T,2u>> part_a; + kel::lbm::data<sch::Particle<sch::T,2u>> part_a; { auto& body = part_a.template get<"rigid_body">(); auto& pos = body.template get<"position">(); @@ -72,7 +72,7 @@ SAW_TEST("Collision Spheroid 2D"){ pos.at({{1u}}) = 0.2; } - saw::data<sch::Particle<sch::T,2u>> part_b; + kel::lbm::data<sch::Particle<sch::T,2u>> part_b; { auto& body = part_b.template get<"rigid_body">(); auto& pos = body.template get<"position">(); @@ -93,7 +93,7 @@ SAW_TEST("Collision Spheroid 2D"){ SAW_TEST("Moving particles 2D"){ using namespace kel; - saw::data<sch::Particle<sch::T,2u>> part_a; + kel::lbm::data<sch::Particle<sch::T,2u>> part_a; { auto& body = part_a.template get<"rigid_body">(); auto& pos = body.template get<"position">(); @@ -110,7 +110,7 @@ SAW_TEST("Moving particles 2D"){ acc.at({{0u}}) = 0.1; } - saw::data<sch::Particle<sch::T,2u>> part_b; + kel::lbm::data<sch::Particle<sch::T,2u>> part_b; { auto& body = part_b.template get<"rigid_body">(); auto& pos = body.template get<"position">(); @@ -127,7 +127,7 @@ SAW_TEST("Moving particles 2D"){ acc.at({{0u}}) = -0.1; } - saw::data<sch::Scalar<sch::T>> dt; + kel::lbm::data<sch::Scalar<sch::T>> dt; dt.at({}).set(0.5); bool has_collided = false; for(uint64_t i = 0u; i < 32u; ++i){ @@ -147,7 +147,7 @@ SAW_TEST("Moving particles 2D"){ SAW_TEST("Particle Matrix Rotation"){ using namespace kel; - saw::data<sch::Particle<sch::T,2u>> part_a; + kel::lbm::data<sch::Particle<sch::T,2u>> part_a; { auto& body = part_a.template get<"rigid_body">(); auto& pos = body.template get<"position">(); @@ -164,7 +164,7 @@ SAW_TEST("Particle Matrix Rotation"){ SAW_TEST("Particle Collision Impulse"){ using namespace kel; - saw::data<sch::Particle<sch::T,2u>> part_a; + kel::lbm::data<sch::Particle<sch::T,2u>> part_a; { auto& body = part_a.template get<"rigid_body">(); auto& pos = body.template get<"position">(); @@ -181,7 +181,7 @@ SAW_TEST("Particle Collision Impulse"){ acc.at({{0u}}) = 0.1; } - saw::data<sch::Particle<sch::T,2u>> part_b; + kel::lbm::data<sch::Particle<sch::T,2u>> part_b; { auto& body = part_b.template get<"rigid_body">(); auto& pos = body.template get<"position">(); @@ -210,15 +210,15 @@ SAW_TEST("Minor Test for mask"){ auto& grid = mask.template get<"grid">(); - for(saw::data<sch::UInt64> i{0u}; i < grid.template get_dim_size<0>(); ++i){ - for(saw::data<sch::UInt64> j{0u}; j < grid.template get_dim_size<1>(); ++j){ + for(kel::lbm::data<sch::UInt64> i{0u}; i < grid.template get_dim_size<0>(); ++i){ + for(kel::lbm::data<sch::UInt64> j{0u}; j < grid.template get_dim_size<1>(); ++j){ std::cout<<grid.at({{i,j}}).get()<<" "; } std::cout<<"\n"; } std::cout<<std::endl; - //saw::data<sch::Array<sch::T,2>> reference_mask{{{4+2,4+2}}}; + //kel::lbm::data<sch::Array<sch::T,2>> reference_mask{{{4+2,4+2}}}; //reference_mask.at({{0,0}}); } */ @@ -228,7 +228,7 @@ SAW_TEST("Verlet integration test 2D"){ lbm::particle_system<sch::T,2,sch::Particle<sch::T,2>> system; { - saw::data<sch::Particle<sch::T,2>> particle; + kel::lbm::data<sch::Particle<sch::T,2>> particle; auto& rb = particle.template get<"rigid_body">(); auto& acc = rb.template get<"acceleration">(); auto& pos = rb.template get<"position">(); @@ -245,21 +245,21 @@ SAW_TEST("Verlet integration test 2D"){ auto& rb = p.template get<"rigid_body">(); auto& pos = rb.template get<"position">(); - for(saw::data<sch::UInt64> i{0u}; i < saw::data<sch::UInt64>{2u}; ++i){ + for(kel::lbm::data<sch::UInt64> i{0u}; i < kel::lbm::data<sch::UInt64>{2u}; ++i){ std::cout<<pos.at(i).get()<<" "; } std::cout<<std::endl; } for(uint64_t i = 0u; i < 36u; ++i){ - system.step(saw::data<sch::T>{1e-1}); + system.step(kel::lbm::data<sch::T>{1e-1}); { auto& p = system.at({0u}); auto& rb = p.template get<"rigid_body">(); auto& pos = rb.template get<"position">(); - for(saw::data<sch::UInt64> i{0u}; i < saw::data<sch::UInt64>{2u}; ++i){ + for(kel::lbm::data<sch::UInt64> i{0u}; i < kel::lbm::data<sch::UInt64>{2u}; ++i){ std::cout<<pos.at(i).get()<<" "; } std::cout<<"\n"; @@ -280,7 +280,7 @@ SAW_TEST("Spheroid Particle / AABB"){ constexpr uint64_t D = 2u; constexpr uint64_t PC = 1u; - saw::data<sch::Scalar<T>> radi,dense; + kel::lbm::data<sch::Scalar<T>> radi,dense; radi.at({}) = 2.2f; dense.at({}) = 1.0f; auto spheroid_pgrp = lbm::create_spheroid_particle_group<T,D,PC>(radi,dense,{8u}); diff --git a/modules/core/tests/vtk_write.cpp b/modules/core/tests/vtk_write.cpp index 1de25bf..b2a5682 100644 --- a/modules/core/tests/vtk_write.cpp +++ b/modules/core/tests/vtk_write.cpp @@ -44,7 +44,7 @@ SAW_TEST("VTK Write test example"){ std::stringstream sstream; - saw::data<sch::Array<sch::MacroStruct<sch::T,2>, 2>> cells{{{2u,2u}}}; + kel::lbm::data<sch::Array<sch::MacroStruct<sch::T,2>, 2>> cells{{{2u,2u}}}; auto& cell_0 = cells.at({{{0,0}}}); cell_0.template get<"momentum">()= {{0.5,-0.1}}; @@ -69,7 +69,7 @@ SAW_TEST("VTK Write raw test example"){ std::stringstream sstream; - saw::data<sch::Array<sch::MacroStruct<sch::T,2>, 2>> cells{{{2u,2u}}}; + kel::lbm::data<sch::Array<sch::MacroStruct<sch::T,2>, 2>> cells{{{2u,2u}}}; auto meta = cells.dims(); |
