Skip to content

Commit

Permalink
Fix findings
Browse files Browse the repository at this point in the history
  • Loading branch information
zzam committed Mar 29, 2024
1 parent d1f78db commit a044616
Showing 1 changed file with 15 additions and 13 deletions.
28 changes: 15 additions & 13 deletions tests/stratagus/test_action_built.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class tested_COrder_Built : public COrder_Built
{
const int progressOnePercent = unit.Type->Stats[0].Costs[TimeCost] * 6;
return testUpdateConstrFrame_Progress(unit, percent * progressOnePercent, initialFrame);
}
}

int testUpdateConstrFrame_Progress(CUnit &unit, int progress, int initialFrame = 9999)
{
Expand All @@ -56,15 +56,17 @@ class tested_COrder_Built : public COrder_Built
};

namespace {
void setFrames(std::vector<CConstructionFrame> &cframes,
const std::vector<std::pair<int, int>>& vec)
std::vector<CConstructionFrame> makeFrames(
const std::vector<std::pair<int, int>>& vec)
{
std::vector<CConstructionFrame> cframes;
const std::size_t size = vec.size();
cframes.resize(size);
for (int i = 0; i < size; ++i) {
cframes[i].Percent = vec[i].first;
cframes[i].Frame = vec[i].second;
}
return cframes;
}
};

Expand All @@ -88,14 +90,14 @@ TEST_CASE("COrder_Built Frame")
}

SUBCASE("size=0") {
setFrames(frames, {});
frames = makeFrames({});

// check unit.Frame is not modified
CHECK(order.testUpdateConstrFrame_Percent(unit, 0, 123) == 123);
}

SUBCASE("size=1") {
setFrames(frames, {
frames = makeFrames({
{0, 0},
});

Expand All @@ -105,7 +107,7 @@ TEST_CASE("COrder_Built Frame")
}

SUBCASE("large steps") {
setFrames(frames, {
frames = makeFrames({
{ 0, 100},
{50, 110},
});
Expand Down Expand Up @@ -133,7 +135,7 @@ TEST_CASE("COrder_Built Frame")

SUBCASE("partially dense")
{
setFrames(frames, {
frames = makeFrames({
{ 0, 0},
{ 1, 1},
{ 2, 2},
Expand Down Expand Up @@ -174,7 +176,7 @@ TEST_CASE("COrder_Built Frame")

SUBCASE("repeated values")
{
setFrames(frames, {
frames = makeFrames({
{ 0, 8},
{ 80, 1},
{ 90, 8},
Expand All @@ -187,7 +189,7 @@ TEST_CASE("COrder_Built Frame")
}

SUBCASE("first key larger") {
setFrames(frames, {
frames = makeFrames({
{ 10, 5},
});

Expand All @@ -197,7 +199,7 @@ TEST_CASE("COrder_Built Frame")

SUBCASE("duplicate keys")
{
setFrames(frames, {
frames = makeFrames({
{ 0, 0},
{ 20, 1},
{ 20, 2},
Expand All @@ -210,7 +212,7 @@ TEST_CASE("COrder_Built Frame")
}

SUBCASE("wrong key order") {
setFrames(frames, {
frames = makeFrames({
{ 75, 9},
{ 50, 8},
{ 0, 7},
Expand All @@ -228,7 +230,7 @@ TEST_CASE("COrder_Built Frame")
}

SUBCASE("too small key value") {
setFrames(frames, {
frames = makeFrames({
{ -1, 7},
{100, 8},
});
Expand All @@ -240,7 +242,7 @@ TEST_CASE("COrder_Built Frame")
}

SUBCASE("too large key value") {
setFrames(frames, {
frames = makeFrames({
{ 0, 7},
{101, 8},
});
Expand Down

0 comments on commit a044616

Please sign in to comment.