Skip to content

Commit

Permalink
Fix core unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
random3940 committed Oct 1, 2024
1 parent b03d413 commit 83a36a1
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 38 deletions.
7 changes: 3 additions & 4 deletions test/style/conversion/stringify.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,9 @@ TEST(Stringify, Color) {
}

TEST(Stringify, VariableAnchorOffsetCollection) {
std::array<float, 2> offset = { 1, 1 };
std::vector<AnchorOffsetPair> test;
test.emplace_back(AnchorOffsetPair{SymbolAnchorType::Left, offset});
ASSERT_EQ(stringify(VariableAnchorOffsetCollection(test)), "[\"left\",[1.0,1.0]]");
std::array<float, 2> offset = {1, 1};
std::vector<AnchorOffsetPair> test{{AnchorOffsetPair{SymbolAnchorType::Left, offset}}};
ASSERT_EQ(stringify(VariableAnchorOffsetCollection(std::move(test))), "[\"left\",[1.0,1.0]]");
}

TEST(Stringify, Array) {
Expand Down
52 changes: 20 additions & 32 deletions test/style/conversion/variable_anchor_offset_collection.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,52 +3,40 @@
#include <mbgl/style/conversion/json.hpp>
#include <mbgl/style/conversion/constant.hpp>
#include <mbgl/style/conversion_impl.hpp>
#include <mbgl/util/variable_anchor_offset_collection.hpp>

// BUGBUG check headers
#include <mbgl/style/expression/dsl.hpp>
#include <mbgl/style/property_expression.hpp>
#include <mbgl/style/conversion/property_value.hpp>
#include <mbgl/util/variable_anchor_offset_collection.hpp>

#include <array>

using namespace mbgl;
using namespace mbgl::style;
using namespace mbgl::style::conversion;

// BUGBUG check if need both
using namespace style::expression;
using namespace style::expression::dsl;

TEST(StyleConversion, VariableAnchorOffsetCollection) {
Error error;
auto fromFunction = [](const char* json) {
auto jsonToExpression = [](const char* json) {
conversion::Error error;
auto function = conversion::convertJSON<PropertyValue<VariableAnchorOffsetCollection>>(
auto propertyValue = conversion::convertJSON<PropertyValue<VariableAnchorOffsetCollection>>(
json, error, /*allowDataExpressions*/ true, /*convertTokens*/ false);
return function->asExpression();
return propertyValue->asExpression();
};

// BUGBUG
// exponential
// interval function
{
auto expr = fromFunction(
R"({"type": "exponential", "stops": [[1, ["left", [0, 0]]], [11, ["left", [10, 20]]]]})");
auto val = expr.evaluate(5);
auto val1 = expr.evaluate(11);
auto expr = jsonToExpression(
R"({"type": "interval", "stops": [[0, ["left", [0, 0]]], [5, ["left", [10, 20]]]]})");

EXPECT_EQ(VariableAnchorOffsetCollection({{{SymbolAnchorType::Left}, {{0, 0}}}}), expr.evaluate(0));
EXPECT_EQ(VariableAnchorOffsetCollection({{{SymbolAnchorType::Left}, {{4, 8}}}}), val); // BUGBUG check value
EXPECT_EQ(VariableAnchorOffsetCollection({{{SymbolAnchorType::Left}, {{10, 20}}}}), val1);
EXPECT_EQ(VariableAnchorOffsetCollection({{{SymbolAnchorType::Left}, {{0, 0}}}}), expr.evaluate(4));
EXPECT_EQ(VariableAnchorOffsetCollection({{{SymbolAnchorType::Left}, {{10, 20}}}}), expr.evaluate(5));
}
// interpolate expression
{
auto expr = jsonToExpression(
R"(["interpolate", ["linear"], ["zoom"], 0, ["literal", ["left", [0, 0]]], 1, ["literal",["left",
[10, 20]]]])");
auto result = expr.evaluate(0.5f);
EXPECT_EQ(VariableAnchorOffsetCollection(std::vector<AnchorOffsetPair>{
{AnchorOffsetPair(SymbolAnchorType::Left, std::array<float, 2>{5.0f, 10.0f})}}),
result);
}

// // BUGBUG
// {
// auto json =
// R"(["interpolate", ["linear"], ["zoom"], 0, ["literal", ["left", [0, 0]]], 1, ["literal",["left",
// [10, 20]]]])";
// PropertyExpression<VariableAnchorOffsetCollection> expr(createExpression(json));
//
// auto result = expr.evaluate(0.5f);
// EXPECT_EQ(VariableAnchorOffsetCollection(), result);
// }
}
4 changes: 2 additions & 2 deletions test/text/cross_tile_symbol_index.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ SymbolInstance makeSymbolInstance(float x, float y, std::u16string key) {
std::array<float, 2> textOffset{{0.0f, 0.0f}};
std::array<float, 2> iconOffset{{0.0f, 0.0f}};
std::array<float, 2> variableTextOffset{{0.0f, 0.0f}};
std::vector<AnchorOffsetPair> anchorOffsets = {{ style::SymbolAnchorType::Left, variableTextOffset }};
VariableAnchorOffsetCollection variableAnchorOffsetCollection(anchorOffsets);
std::vector<AnchorOffsetPair> anchorOffsets = {{style::SymbolAnchorType::Left, variableTextOffset}};
VariableAnchorOffsetCollection variableAnchorOffsetCollection(std::move(anchorOffsets));
style::SymbolPlacementType placementType = style::SymbolPlacementType::Point;

auto sharedData = std::make_shared<SymbolInstanceSharedData>(std::move(line),
Expand Down

0 comments on commit 83a36a1

Please sign in to comment.