Skip to content

Commit 7526288

Browse files
committed
Added unit tests for the functions in calculate.cpp
1 parent 2821d59 commit 7526288

7 files changed

Lines changed: 447 additions & 7 deletions

File tree

src/MieSimulatorGUI.pro

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
TEMPLATE = subdirs
22

33
SUBDIRS += \
4-
app
4+
app \
5+
test

src/app/calc/calculate.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,11 @@ void calculate::SetSphereRadiusAndRefIndex(parameters *para, unsigned int index,
355355

356356
if (para->nRadius == 1) //Mono Disperse
357357
{
358+
if (flagVolOrConc) //If volume fraction is selected, update number density
359+
{
360+
double sphereVolume = 4.0 * M_PI *para->meanRadius * para->meanRadius * para->meanRadius / 3.0;
361+
para->sphNumDensity = 1e9 * para->volFraction /sphereVolume ;
362+
}
358363
para->radArray[0] = para->meanRadius;
359364
para->numDensityArray[0] = para->sphNumDensity;
360365
para->scatRefRealArray[0] = para->scatRefReal;

src/app/dialog/mainwindow.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ void MainWindow::on_pushButton_RunSimulation_clicked()
102102
//Mono disperse
103103
if (ui->radioButton_MonoDisperse->isChecked())
104104
{
105-
support.ProcessDistribution(ui, mPara, 3);
105+
support.ProcessDistribution(ui, mPara, 3); // index = 3: mono disperse
106106
support.ProcessMonoDisperse(ui,mPara);
107107
ui->label_Progress->setText("<font color=\"green\"> Completed!</font>");
108108
ui->slider_ConcPercentChange->setValue(0);

src/app/dialog/mainwindowsupport.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -128,11 +128,6 @@ void MainWindowSupport::LoadInputData(Ui_MainWindow *ui, parameters *para)
128128
{
129129
para->meanRadius = 0.5 * ui->lineEdit_Diameter->text().toDouble();
130130
para->nRadius = 1;
131-
if (ui->radioButton_VolFrac->isChecked())
132-
{
133-
double volume = 4.0 * M_PI *para->meanRadius * para->meanRadius * para->meanRadius / 3.0;
134-
para->sphNumDensity = para->volFraction * 1e9 /volume ;
135-
}
136131
}
137132
if ((ui->radioButton_PolyDisperse->isChecked()) && (ui->comboBox_Distribution->currentIndex() != 2))
138133
{

src/test/test.pro

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# This is the project file for the unit test.
2+
3+
# Set the template to create an application executable.
4+
TEMPLATE = app
5+
6+
# Add the Qt Test library, which is required for unit testing.
7+
# We also include 'widgets' as the app under test is a GUI app,
8+
# and some functions might implicitly require it (though not directly in 'calculate').
9+
QT += testlib widgets
10+
11+
# The target name for our test executable.
12+
TARGET = test_calculate
13+
14+
# Configure the build to be in debug and release modes.
15+
CONFIG += warn_on console
16+
17+
# Include the headers from the main application to access the classes we want to test.
18+
INCLUDEPATH += ../app \
19+
../app/calc
20+
21+
# Add the sources for our test suite and the classes we are testing.
22+
# We include the calculate.cpp directly, as well as mock implementations for its dependencies.
23+
# The `mock_` files are simple stubs that allow us to test the `calculate` class in isolation.
24+
SOURCES += \
25+
test_calculate.cpp \
26+
../app/parameters.cpp \
27+
../app/calc/calculate.cpp \
28+
../app/calc/miesimulation.cpp \
29+
../app/calc/utilities.cpp
30+
31+
# Add the headers for the test suite and the classes we are testing.
32+
HEADERS += \
33+
test_calculate.h \
34+
../app/parameters.h \
35+
../app/calc/calculate.h \
36+
../app/calc/miesimulation.h \
37+
../app/calc/utilities.h
38+
39+
# Define some preprocessor macros if needed.
40+
DEFINES += QT_TESTLIB_WIDGETS_LIB

0 commit comments

Comments
 (0)