blob: a2e9dfe3e3e981d93ebaea2d79984ed96f73e139 [file] [edit]
// Copyright 2025 Google Inc. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include "edge_weights.h"
#include "graph.h"
#include "test.h"
TEST(EdgeWeightsTest, TestEmpty) {
std::string content;
EdgeWeights edge_weights;
ParseEdgeWeights(content, edge_weights);
EXPECT_EQ(0, edge_weights.size());
}
TEST(EdgeWeightsTest, TestValidWeights) {
std::string content(
"some/path,5\n"
"some/other_path,7\n"
);
EdgeWeights edge_weights;
ParseEdgeWeights(content, edge_weights);
EXPECT_EQ(2, edge_weights.size());
EXPECT_EQ(5, edge_weights["some/path"]);
EXPECT_EQ(7, edge_weights["some/other_path"]);
}
TEST(EdgeWeightsTest, TestInvalidLines) {
std::string content(
"# foo some other thing\n"
"this is a string,,,with too many comma's\n"
"some/path,1234\n"
"some/other_path,5678\n"
);
EdgeWeights edge_weights;
ParseEdgeWeights(content, edge_weights);
EXPECT_EQ(2, edge_weights.size());
EXPECT_EQ(1234, edge_weights["some/path"]);
EXPECT_EQ(5678, edge_weights["some/other_path"]);
}
TEST(EdgeWeightsTest, TestInvalidWeights) {
std::string content(
"some/path_with,invalid_weight\n"
"some/invalid_weight,56h\n"
"some/invalid_weight,0x56\n"
"some/path,9876\n"
"some/other_path,5432\n"
);
EdgeWeights edge_weights;
ParseEdgeWeights(content, edge_weights);
EXPECT_EQ(2, edge_weights.size());
EXPECT_EQ(9876, edge_weights["some/path"]);
EXPECT_EQ(5432, edge_weights["some/other_path"]);
}
TEST(EdgeWeightsTest, NoNegativeWeights) {
std::string content(
"some/negative_weight,-45\n"
"some/path,9876\n"
"some/other_path,5432\n"
);
EdgeWeights edge_weights;
ParseEdgeWeights(content, edge_weights);
EXPECT_EQ(2, edge_weights.size());
EXPECT_EQ(9876, edge_weights["some/path"]);
EXPECT_EQ(5432, edge_weights["some/other_path"]);
}
TEST(EdgeWeightsTest, MaxWeightValue) {
std::string content(
"some/max_weight,9223372036854775807\n"
"some/over_max_weight,9223372036854775808\n"
);
EdgeWeights edge_weights;
ParseEdgeWeights(content, edge_weights);
EXPECT_EQ(1, edge_weights.size());
EXPECT_EQ(9223372036854775807, edge_weights["some/max_weight"]);
}
TEST(EdgeWeightsTest, FirstOneWins) {
std::string content(
"some/path,42\n"
"some/other_path,7\n"
"some/path,55"
);
EdgeWeights edge_weights;
ParseEdgeWeights(content, edge_weights);
EXPECT_EQ(2, edge_weights.size());
EXPECT_EQ(42, edge_weights["some/path"]);
EXPECT_EQ(7, edge_weights["some/other_path"]);
}