Skip to content

Commit b9c7b2e

Browse files
imikejacksonclaude
andauthored
TEST: Create unit tests for all classes where possible (#38)
* ENH: Add unit tests for 8 high-priority classes with no/minimal coverage Add comprehensive Catch2 unit tests for: - Matrix3X1<T>: construction, dot, cross, magnitude, normalize, sortAscending, cosTheta, operators (20 tests) - Matrix3X3<T>: construction, multiply, transpose, determinant, invert, adjoint, col/row, DirectStructureMatrix (23 tests) - ArrayHelpers<T,K>: splat, multiply, scalarMultiply, scalarDivide, sum, sumofSquares, maxval, absValue, power (13 tests) - EbsdDataArray<T>: CreateArray, FromStdVector, CopyFromPointer, get/set, components, resize, erase, deepCopy, copyFromArray (23 tests) - EbsdStringUtils: split (single/multi delimiter, consecutive), specific_split, replace, ltrim, rtrim, trimmed, chop, number, simplified (18 tests) - EbsdTransform: IdentifyStandardTransformation for TSL, HKL, HEDM, and unknown parameters (6 tests) - EbsdLibRandom: seeded deterministic output, range checks for real1/real2/real3/res53/int31, init_by_array (9 tests) - OrientationMath: MetricTensor, RootTensor, Miller-Bravais conversions with round-trip verification (12 tests) Also documents newly discovered Bug #5: EbsdDataArray::eraseTuples() does not update m_NumTuples. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * ENH: Add unit tests for 9 medium-priority classes (#13-#21) Add 80 new test cases across 9 test files covering ColorTable/ColorUtilities, LambertUtilities, ModifiedLambertProjection, ComputeStereographicProjection, TexturePreset, AngPhase/CtfPhase/EspritPhase, LaueOps subclasses, ModifiedLambertProjection3D, and OrientationTransformation known-value tests. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * ENH: Add unit tests for 6 low-priority classes (#23-#28) and fix ToolTipGenerator bug Add 44 new test cases covering ToolTipGenerator, PoleFigureData, CanvasUtilities, ModifiedLambertProjectionArray, PoleFigureUtilities, and TiffWriter. Fix bug in ToolTipGenerator::generateHTML() and rowToHTML() where both methods returned an empty string instead of the stringstream content. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * BUG: Replace M_PI with ebsdlib::constants::k_PiD in LambertUtilitiesTest M_PI is not defined on Windows without _USE_MATH_DEFINES. Use the project's own constant to ensure cross-platform compilation. --------- Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 1d7b2e4 commit b9c7b2e

30 files changed

Lines changed: 4025 additions & 26 deletions

CLAUDE.md

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
# Project Guidelines for Claude
2+
3+
## Project Overview
4+
5+
### Phase 1
6+
I would like to add more unit testing to the EbsdLib library. Can we put together a TODO.md file stored in the "Code_Review" directory that lists all the candidate classes to create unit tests for?
7+
8+
### Phase 2
9+
I would also like to write documentation for this library
10+
11+
### Phase 3
12+
I would also like to write more example code that shows how to use the library
13+
14+
How should we get stated with these tasks?
15+
16+
## Directory Structure
17+
- `Source/Ebsdlib/` - Core library
18+
- `Source/Apps/` - various test applications
19+
- `src/Test/` - Test files
20+
- `cmake/` - CMake configuration
21+
22+
23+
## Directories to Ignore
24+
- `scripts/` - Build/utility scripts
25+
- `conda/` - Conda packaging
26+
27+
## Coding Standards
28+
29+
### C++ Style (from .clang-format)
30+
- C++20 standard
31+
- Allman brace style (braces on new lines for classes, control statements, enums, functions, namespaces, structs, before else)
32+
- 200 column limit
33+
- 2-space indentation, no tabs
34+
- Pointer alignment left (`int* ptr` not `int *ptr`)
35+
- No space before parentheses
36+
- Sort includes alphabetically
37+
- No short functions on single line
38+
- Always break template declarations
39+
- Constructor initializers break before comma
40+
41+
### Naming Conventions (from .clang-tidy)
42+
- C++ header files: `.hpp` extension
43+
- C++ source files: `.cpp` extension
44+
- Namespaces: `lower_case`
45+
- Classes: `CamelCase`
46+
- Structs: `CamelCase`
47+
- Class methods: `camelBack`
48+
- Functions: `camelBack`
49+
- Variables: `camelBack`
50+
- Private members: `m_` prefix + `CamelCase` (e.g., `m_MemberVariable`)
51+
- Global variables: `CamelCase`
52+
- Global constants: `k_` prefix + `CamelCase` (e.g., `k_DefaultValue`)
53+
- Local pointers: `camelBack` + `Ptr` suffix (e.g., `dataPtr`)
54+
- Type aliases: `CamelCase` + `Type` suffix (e.g., `ValueType`)
55+
- Macros: `UPPER_CASE`
56+
57+
58+
## Build System
59+
- vcpkg for dependency management
60+
- CMake-based build system
61+
62+
Example configuring the project
63+
```bash
64+
cd /Users/mjackson/Workspace1/EbsdLib && cmake --preset EbsdLib-Release
65+
```
66+
67+
- Build directory is located at "/Users/mjackson/Workspace1/DREAM3D-Build/EbsdLib-Release"
68+
69+
Example building the project
70+
```bash
71+
cd /Users/mjackson/Workspace5/DREAM3D-Build/EbsdLib-Release && cmake --build . --target all
72+
```
73+
74+
- Python anaconda environment 'dream3d' can be used if needed
75+
76+
## Testing
77+
- Unit tests use the Catch2 framework.
78+
- Use the `ctest` to run unit tests
79+
80+
### Running Unit Tests
81+
- Always use `ctest` to run unit tests, NOT the test binary directly
82+
- The `ctest` command handles test data extraction and cleanup automatically
83+
- Use the `-R` flag to run specific tests by name pattern
84+
85+
Example - Running a specific test:
86+
```bash
87+
cd /Users/mjackson/Workspace5/DREAM3D-Build/EbsdLib-Release && ctest -R "EbsdLib::FillBadData" --verbose
88+
```
89+
90+
Example - Running all SimplnxCore tests:
91+
```bash
92+
cd /Users/mjackson/Workspace5/DREAM3D-Build/EbsdLib-Release && ctest -R "EbsdLib::" --verbose
93+
```
94+
95+
### Printing debug statements in unit tests
96+
97+
## Additional Notes
98+
<!-- Add any other project-specific rules here -->

Code_Review/TODO.md

Lines changed: 29 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,12 @@ There are **12 active test files** compiled into a single `EbsdLibUnitTest` exec
5959
**Severity:** MEDIUM - Tests pass even with wildly incorrect values
6060
**Issue:** The tolerance check uses `delta < 1.0E6` (one million) instead of `1.0E-6` (one millionth). This means the round-trip conversion tests will pass even if values are off by up to a million, making the tests effectively useless for catching conversion errors.
6161

62+
### Bug 5: `EbsdDataArray::eraseTuples()` - Does not update `m_NumTuples`
63+
64+
**File:** `Source/EbsdLib/Core/EbsdDataArray.cpp:678`
65+
**Severity:** MEDIUM - `getNumberOfTuples()` returns stale value after eraseTuples
66+
**Issue:** The `eraseTuples()` method updates `m_Size`, `m_MaxId`, and `m_Array` but never updates `m_NumTuples`. After calling `eraseTuples()`, `getNumberOfTuples()` returns the original tuple count instead of the new (reduced) count. `getSize()` correctly returns the new total element count.
67+
6268
---
6369

6470
## Classes Requiring Unit Tests
@@ -70,7 +76,7 @@ These classes have zero or near-zero test coverage and contain non-trivial logic
7076
#### 1. `EbsdDataArray<T>` - Core data container
7177

7278
- **File:** `Source/EbsdLib/Core/EbsdDataArray.hpp`
73-
- **Status:** No tests
79+
- **Status:** **DONE** - `Source/Test/EbsdDataArrayTest.cpp` (23 test cases)
7480
- **Why:** Core template class used by virtually every reader and computation. Wraps raw arrays with lifecycle management.
7581
- **Recommended tests:**
7682
- Construction (default, sized, from existing pointer)
@@ -85,7 +91,7 @@ These classes have zero or near-zero test coverage and contain non-trivial logic
8591
#### 2. `Matrix3X1<T>` - 3x1 vector operations
8692

8793
- **File:** `Source/EbsdLib/Math/Matrix3X1.hpp`
88-
- **Status:** Only `cosTheta` tested (in QuaternionTest)
94+
- **Status:** **DONE** - `Source/Test/Matrix3X1Test.cpp` (20 test cases)
8995
- **Why:** Core math class with known bugs (see Bugs #1 and #2)
9096
- **Recommended tests:**
9197
- Construction and element access
@@ -99,7 +105,7 @@ These classes have zero or near-zero test coverage and contain non-trivial logic
99105
#### 3. `Matrix3X3<T>` - 3x3 matrix operations
100106

101107
- **File:** `Source/EbsdLib/Math/Matrix3X3.hpp`
102-
- **Status:** Exercised in TextureTest but no assertions on results
108+
- **Status:** **DONE** - `Source/Test/Matrix3X3Test.cpp` (23 test cases)
103109
- **Why:** Used in orientation math, coordinate transforms; currently only smoke-tested
104110
- **Recommended tests:**
105111
- Construction and element access
@@ -145,7 +151,7 @@ These classes have zero or near-zero test coverage and contain non-trivial logic
145151
#### 7. `OrientationMath` - Crystallographic math
146152

147153
- **File:** `Source/EbsdLib/Core/OrientationMath.h`
148-
- **Status:** No direct tests (indirectly exercised by ConvertToFundamentalZoneTest)
154+
- **Status:** **DONE** - `Source/Test/OrientationMathTest.cpp` (12 test cases)
149155
- **Why:** Static methods for misorientation calculations, widely used
150156
- **Recommended tests:**
151157
- `axisAngletoMatrix()`, `quatsToMatrix()`
@@ -156,7 +162,7 @@ These classes have zero or near-zero test coverage and contain non-trivial logic
156162
#### 8. `EbsdStringUtils` - String utilities
157163

158164
- **File:** `Source/EbsdLib/Utilities/EbsdStringUtils.hpp`
159-
- **Status:** No tests
165+
- **Status:** **DONE** - `Source/Test/EbsdStringUtilsTest.cpp` (18 test cases)
160166
- **Why:** String parsing utilities used by all readers
161167
- **Recommended tests:**
162168
- `split()`, `tokenize()` with various delimiters
@@ -168,7 +174,7 @@ These classes have zero or near-zero test coverage and contain non-trivial logic
168174
#### 9. `EbsdTransform` - Reference frame transformations
169175

170176
- **File:** `Source/EbsdLib/Core/EbsdTransform.h`
171-
- **Status:** No tests
177+
- **Status:** **DONE** - `Source/Test/EbsdTransformTest.cpp` (6 test cases)
172178
- **Why:** Transforms sample and Euler reference frames; errors here corrupt all downstream analysis
173179
- **Recommended tests:**
174180
- Sample reference frame transformations (all axis combinations)
@@ -179,7 +185,7 @@ These classes have zero or near-zero test coverage and contain non-trivial logic
179185
#### 10. `EbsdLibRandom` - PRNG
180186

181187
- **File:** `Source/EbsdLib/Math/EbsdLibRandom.h`
182-
- **Status:** No tests
188+
- **Status:** **DONE** - `Source/Test/EbsdLibRandomTest.cpp` (9 test cases)
183189
- **Why:** Mersenne Twister wrapper; used for texture generation
184190
- **Recommended tests:**
185191
- Seeded deterministic output verification
@@ -189,7 +195,7 @@ These classes have zero or near-zero test coverage and contain non-trivial logic
189195
#### 11. `ArrayHelpers<T,K>` - Template math helpers
190196

191197
- **File:** `Source/EbsdLib/Math/ArrayHelpers.hpp`
192-
- **Status:** No tests
198+
- **Status:** **DONE** - `Source/Test/ArrayHelpersTest.cpp` (13 test cases)
193199
- **Why:** Static utility methods used in orientation conversions
194200
- **Recommended tests:**
195201
- `splat()`, `multiply()`, `scalarMultiply()`
@@ -213,43 +219,43 @@ These classes have zero or near-zero test coverage and contain non-trivial logic
213219
#### 13. `ColorTable` / `ColorUtilities` - Color handling
214220

215221
- **Files:** `Source/EbsdLib/Utilities/ColorTable.h`, `Source/EbsdLib/Utilities/ColorUtilities.h`
216-
- **Status:** No direct tests
222+
- **Status:** **DONE** - `Source/Test/ColorTableTest.cpp` (11 test cases)
217223
- **Recommended tests:** `RgbColor` helpers, HSV-to-RGB conversion, color component extraction
218224

219225
#### 14. `LambertUtilities` - Square-to-sphere mapping
220226

221227
- **File:** `Source/EbsdLib/Utilities/LambertUtilities.h`
222-
- **Status:** No tests
228+
- **Status:** **DONE** - `Source/Test/LambertUtilitiesTest.cpp` (4 test cases)
223229
- **Recommended tests:** Square-to-sphere and sphere-to-square conversions, round-trip consistency, boundary values
224230

225231
#### 15. `ModifiedLambertProjection` - Lambert projection
226232

227233
- **File:** `Source/EbsdLib/Utilities/ModifiedLambertProjection.h`
228-
- **Status:** No tests
234+
- **Status:** **DONE** - `Source/Test/ModifiedLambertProjectionTest.cpp` (7 test cases)
229235
- **Recommended tests:** North/south hemisphere projection, `addInterpolatedValues()`, normalization
230236

231237
#### 16. `ComputeStereographicProjection` - Stereographic projection utilities
232238

233239
- **File:** `Source/EbsdLib/Utilities/ComputeStereographicProjection.h`
234-
- **Status:** No tests
240+
- **Status:** **DONE** - `Source/Test/StereographicProjectionTest.cpp` (6 test cases)
235241
- **Recommended tests:** Stereographic-to-spherical and spherical-to-stereographic round-trips
236242

237243
#### 17. `TexturePreset` - Texture presets
238244

239245
- **File:** `Source/EbsdLib/Texture/TexturePreset.h`
240-
- **Status:** No tests
246+
- **Status:** **DONE** - `Source/Test/TexturePresetTest.cpp` (5 test cases)
241247
- **Recommended tests:** Preset value getters, preset registration
242248

243249
#### 18. `AngPhase` / `CtfPhase` / `EspritPhase` - Phase data classes
244250

245251
- **Files:** `Source/EbsdLib/IO/TSL/AngPhase.h`, `Source/EbsdLib/IO/HKL/CtfPhase.h`, `Source/EbsdLib/IO/BrukerNano/EspritPhase.h`
246-
- **Status:** CtfPhase partially tested via CtfReaderTest; others untested
252+
- **Status:** **DONE** - `Source/Test/PhaseTest.cpp` (18 test cases)
247253
- **Recommended tests:** Construction, getter/setter verification, lattice constant parsing
248254

249255
#### 19. LaueOps subclasses - Enhanced symmetry tests
250256

251257
- **Files:** `Source/EbsdLib/LaueOps/*.h` (11 subclasses)
252-
- **Status:** FZ tests comprehensive; IPF generation and misorientation calculation only smoke-tested
258+
- **Status:** **DONE** - `Source/Test/LaueOpsTest.cpp` (11 test cases)
253259
- **Recommended tests:**
254260
- `getNumSymOps()` returns expected count for each crystal system
255261
- `getIPFColor()` with known orientations against reference values
@@ -259,13 +265,13 @@ These classes have zero or near-zero test coverage and contain non-trivial logic
259265
#### 20. `ModifiedLambertProjection3D<T,K>` - 3D Lambert projection
260266

261267
- **File:** `Source/EbsdLib/Utilities/ModifiedLambertProjection3D.hpp`
262-
- **Status:** No tests
268+
- **Status:** **DONE** - `Source/Test/ModifiedLambertProjection3DTest.cpp` (7 test cases)
263269
- **Recommended tests:** Cube-to-sphere and sphere-to-cube conversions, edge cases at cube boundaries
264270

265271
#### 21. `OrientationTransformation` (namespace) - Conversion functions
266272

267273
- **File:** `Source/EbsdLib/Core/OrientationTransformation.hpp`
268-
- **Status:** Well-tested via OrientationTest.cpp (round-trip), but not all individual functions are directly tested
274+
- **Status:** **DONE** - `Source/Test/OrientationTransformationTest.cpp` (11 test cases)
269275
- **Recommended tests:** Direct tests of each `xx2yy()` function with known analytical values (supplement existing round-trip tests)
270276

271277
#### 22. `H5CtfReader` / `H5AngReader` - HDF5 format readers
@@ -281,37 +287,37 @@ These classes have zero or near-zero test coverage and contain non-trivial logic
281287
#### 23. `ToolTipGenerator` - HTML tooltip builder
282288

283289
- **File:** `Source/EbsdLib/Utilities/ToolTipGenerator.h`
284-
- **Status:** No tests
290+
- **Status:** **DONE** - `Source/Test/ToolTipGeneratorTest.cpp` (8 test cases). Also fixed bug where `generateHTML()` and `rowToHTML()` returned empty strings.
285291
- **Recommended tests:** `addTitle()`, `addValue()`, output HTML correctness
286292

287293
#### 24. `PoleFigureData` - Data holder
288294

289295
- **File:** `Source/EbsdLib/Utilities/PoleFigureData.h`
290-
- **Status:** No tests
296+
- **Status:** **DONE** - `Source/Test/PoleFigureDataTest.cpp` (5 test cases)
291297
- **Recommended tests:** Construction, getter verification
292298

293299
#### 25. `CanvasUtilities` - Visualization helpers
294300

295301
- **File:** `Source/EbsdLib/Utilities/CanvasUtilities.hpp`
296-
- **Status:** No tests
302+
- **Status:** **DONE** - `Source/Test/CanvasUtilitiesTest.cpp` (6 test cases)
297303
- **Recommended tests:** Only if visual regression testing infrastructure is added
298304

299305
#### 26. `ModifiedLambertProjectionArray` - Array variant
300306

301307
- **File:** `Source/EbsdLib/Utilities/ModifiedLambertProjectionArray.h`
302-
- **Status:** No tests
308+
- **Status:** **DONE** - `Source/Test/ModifiedLambertProjectionArrayTest.cpp` (16 test cases)
303309
- **Recommended tests:** Array construction, element access, resize
304310

305311
#### 27. `PoleFigureUtilities` - Pole figure generation
306312

307313
- **File:** `Source/EbsdLib/Utilities/PoleFigureUtilities.h`
308-
- **Status:** No tests
314+
- **Status:** **DONE** - `Source/Test/PoleFigureUtilitiesTest.cpp` (4 test cases)
309315
- **Recommended tests:** Configuration setup, pole figure generation with known inputs
310316

311317
#### 28. `TiffWriter` - TIFF file output
312318

313319
- **File:** `Source/EbsdLib/Utilities/TiffWriter.h`
314-
- **Status:** Indirectly tested via IPFLegendTest (only checks return code)
320+
- **Status:** **DONE** - `Source/Test/TiffWriterTest.cpp` (4 test cases)
315321
- **Recommended tests:** Write and read-back verification, grayscale and color modes
316322

317323
---

Source/EbsdLib/Math/Matrix3X1.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#pragma once
22

3+
#include <array>
34
#include <cmath>
45
#include <memory>
56

Source/EbsdLib/Math/Matrix3X3.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
#include <Eigen/Dense>
77

8+
#include <array>
89
#include <cassert>
910
#include <cmath>
1011

Source/EbsdLib/Utilities/PoleFigureUtilities.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ class EbsdLib_EXPORT PoleFigureUtilities
148148
* @brief The GeneratePoleFigureRgbaImageImpl class is a wrapper around generating the RGBA image (2D UChar Array with 4 Components) from the
149149
* intensity image. This should be called from a TBB Task
150150
*/
151-
class GeneratePoleFigureRgbaImageImpl
151+
class EbsdLib_EXPORT GeneratePoleFigureRgbaImageImpl
152152
{
153153
public:
154154
GeneratePoleFigureRgbaImageImpl(ebsdlib::DoubleArrayType* intensity, PoleFigureConfiguration_t* config, ebsdlib::UInt8ArrayType* rgba);

Source/EbsdLib/Utilities/ToolTipGenerator.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ std::string ToolTipGenerator::generateHTML() const
122122
ss << rowToHTML(spacer);
123123
ss << "</tbody></table>\n";
124124
ss << "</body></html>";
125-
return html;
125+
return ss.str();
126126
}
127127

128128
// -----------------------------------------------------------------------------
@@ -144,5 +144,5 @@ std::string ToolTipGenerator::rowToHTML(const RowItem& row) const
144144
break;
145145
}
146146

147-
return html;
147+
return ss.str();
148148
}

0 commit comments

Comments
 (0)