Skip to content

Commit

Permalink
further tests for strength editing
Browse files Browse the repository at this point in the history
  • Loading branch information
chrxh committed Nov 22, 2024
1 parent a0437a0 commit 0b3cd8b
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 2 deletions.
1 change: 1 addition & 0 deletions source/EngineInterface/SimulationParametersEditService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ auto SimulationParametersEditService::calcRadiationStrengthsForDeletingSpot(
}
}
if (!existsUnpinned) {
result.values.at(0) += strengths.values.at(deleteIndex);
result.pinned.erase(0);
}

Expand Down
61 changes: 61 additions & 0 deletions source/EngineTests/SimulationParametersEditServiceTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -351,3 +351,64 @@ TEST_F(SimulationParametersEditServiceTests, calcRadiationStrengthsForAddingSpot
checkApproxEqual(0.0f, strengths.values[3]);
EXPECT_EQ(origStrengths.pinned, strengths.pinned);
}

TEST_F(SimulationParametersEditServiceTests, calcRadiationStrengthsForDeletingSpot_allUnpinned)
{
RadiationStrengths origStrengths;
origStrengths.values = {0.1f, 0.3f, 0.6f};
origStrengths.pinned = {};

auto strengths = SimulationParametersEditService::get().calcRadiationStrengthsForDeletingSpot(origStrengths, 1);

ASSERT_EQ(2, strengths.values.size());

auto factor = 1.0f + 0.3f / 0.7f;
checkApproxEqual(0.1f * factor, strengths.values[0]);
checkApproxEqual(0.6f * factor, strengths.values[1]);
EXPECT_EQ(std::set<int>{}, strengths.pinned);
}

TEST_F(SimulationParametersEditServiceTests, calcRadiationStrengthsForDeletingSpot_basePinned)
{
RadiationStrengths origStrengths;
origStrengths.values = {0.1f, 0.3f, 0.6f};
origStrengths.pinned = {0};

auto strengths = SimulationParametersEditService::get().calcRadiationStrengthsForDeletingSpot(origStrengths, 1);

ASSERT_EQ(2, strengths.values.size());

checkApproxEqual(0.1f, strengths.values[0]);
checkApproxEqual(0.9f, strengths.values[1]);
EXPECT_EQ(std::set<int>{0}, strengths.pinned);
}

TEST_F(SimulationParametersEditServiceTests, calcRadiationStrengthsForDeletingSpot_spotPinned)
{
RadiationStrengths origStrengths;
origStrengths.values = {0.1f, 0.3f, 0.6f};
origStrengths.pinned = {2};

auto strengths = SimulationParametersEditService::get().calcRadiationStrengthsForDeletingSpot(origStrengths, 1);

ASSERT_EQ(2, strengths.values.size());

checkApproxEqual(0.4f, strengths.values[0]);
checkApproxEqual(0.6f, strengths.values[1]);
EXPECT_EQ(std::set<int>{1}, strengths.pinned);
}

TEST_F(SimulationParametersEditServiceTests, calcRadiationStrengthsForDeletingSpot_allPinned)
{
RadiationStrengths origStrengths;
origStrengths.values = {0.1f, 0.3f, 0.6f};
origStrengths.pinned = {0, 1, 2};

auto strengths = SimulationParametersEditService::get().calcRadiationStrengthsForDeletingSpot(origStrengths, 1);

ASSERT_EQ(2, strengths.values.size());

checkApproxEqual(0.4f, strengths.values[0]);
checkApproxEqual(0.6f, strengths.values[1]);
EXPECT_EQ(std::set<int>{1}, strengths.pinned);
}
4 changes: 2 additions & 2 deletions source/Gui/RadiationSourcesWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ void RadiationSourcesWindow::processBaseTab()
auto editedStrength = strength;
if (AlienImGui::SliderFloat(
AlienImGui::SliderFloatParameters()
.name("Strength ratio")
.name("Strength")
.textWidth(RightColumnWidth)
.min(0.0f)
.max(1.0f)
Expand Down Expand Up @@ -132,7 +132,7 @@ bool RadiationSourcesWindow::processSourceTab(int index)
auto origStrengths = editService.getRadiationStrengths(parameters);
if (AlienImGui::SliderFloat(
AlienImGui::SliderFloatParameters()
.name("Strength ratio")
.name("Strength")
.textWidth(RightColumnWidth)
.min(0.0f)
.max(1.0f)
Expand Down

0 comments on commit 0b3cd8b

Please sign in to comment.