Skip to content

Add comprehensive unit and integration tests for engine/nn layers and functions#281

Merged
mldiego merged 47 commits intomasterfrom
copilot/fix-5595ad52-e646-4345-9f99-f2aab25ff64b
Oct 14, 2025
Merged

Add comprehensive unit and integration tests for engine/nn layers and functions#281
mldiego merged 47 commits intomasterfrom
copilot/fix-5595ad52-e646-4345-9f99-f2aab25ff64b

Conversation

Copy link
Contributor

Copilot AI commented Oct 3, 2025

Overview

This PR implements comprehensive unit and integration test coverage for layers and functions in the code/nnv/engine/nn directory, addressing the request to create tests for "every layer and function in the engine directory."

What's New

Created 19 new test files containing ~185 unit tests with ~5,900 lines of test code, achieving:

  • 100% coverage of all function tests (2/2 functions)
  • 56% coverage of TODO layer placeholders (19/34 layers)
  • 65% overall layer coverage (28/43 total layers now have tests)

Tests Added

Functions (2/2 - 100% Complete)

  • LeakyReLU - Tests for evaluate, reach methods (exact-star, approx-star, approx-zono), and stepReach with gamma parameter
  • Sign - Tests for polar/nonnegative modes, get_sign_lb/ub, stepReach, and reach methods

Layers (19 layers completed)

Activation Layers:

  • HardSigmoidLayer, SigmoidLayer, SignLayer, SoftmaxLayer, TanhLayer
  • SaturatingLinearLayer (clips to [0,1]), SaturatingLinearSymmLayer (clips to [-1,1])

Input Layers:

  • FeatureInputLayer (with normalization support)
  • SequenceInputLayer (for sequence data)
  • PixelClassificationLayer (for segmentation)

Structural Layers:

  • AdditionLayer (element-wise addition with MinkowskiSum)
  • ConcatenationLayer (concatenation along arbitrary dimensions)
  • DepthConcatenationLayer (channel concatenation)
  • FlattenLayer (MATLAB/Keras/ONNX flatten styles)
  • ReshapeLayer (with targetDim and -1 handling)
  • UpsampleLayer (with scale factors)
  • PlaceholderLayer (no-op pass-through)

Test Coverage Details

Each test suite comprehensively validates:

  1. Constructors - Default, parameterized, and validation testing
  2. Evaluation - evaluate() and evaluateSequence() methods with various input types
  3. Reachability - Support for ImageStar, ImageZono, Star, and Zono inputs
  4. Methods - exact-star, approx-star, and approx-zono reachability methods
  5. GPU Support - toGPU() functionality
  6. Precision - changeParamsPrecision() for single/double precision
  7. Edge Cases - Boundary values, numerical stability, and type validation

Testing Philosophy

Minimal Changes:

  • Only replaced empty todo_test.m files with actual tests
  • No modifications to engine code
  • Follows existing repository test patterns and structure

Consistency:

  • All tests use MATLAB's unit testing framework
  • Consistent naming: test_<LayerName>.m
  • Similar structure across all test files
  • Can be run with runtests('test_<LayerName>')

Example Test Usage

% Run tests for a specific layer
results = runtests('test_SigmoidLayer')

% Run tests for a specific function
results = runtests('test_LeakyReLU')

% Run all layer tests
results = runtests('code/nnv/tests/nn/layers')

What's Not Included

Remaining TODO Layers (11) - Complex layers requiring additional dependencies:

  • AveragePooling3DLayer, BatchNormalizationLayer, Conv1DLayer, Conv3DLayer
  • ElementwiseAffineLayer, GlobalAveragePooling1DLayer, ODEblockLayer
  • TransposeConv1DLayer

Layers Without Test Directories (11) - Would require creating new test directories:

  • ActivationFunctionLayer (abstract base class)
  • Image3DInputLayer, LayerNormalizationLayer, LeakyReluLayer, LstmLayer
  • RecurrentLayer, ReshapeToConcatenationLayer, Resize2DLayer, TransposedConv1DLayer

These can be addressed in future PRs as needed.

Impact

This PR significantly improves test coverage for the NNV engine directory, providing:

  • ✅ Validation of layer functionality
  • ✅ Regression testing capabilities
  • ✅ Documentation through test examples
  • ✅ Confidence in neural network verification operations

All tests follow minimal change principles and maintain consistency with the existing codebase.

Original prompt

Can you create unit and integration tests for every layer and function in the endine directory?


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 5 commits October 3, 2025 16:43
Co-authored-by: mldiego <39501815+mldiego@users.noreply.github.com>
Co-authored-by: mldiego <39501815+mldiego@users.noreply.github.com>
…nd HardSigmoidLayer

Co-authored-by: mldiego <39501815+mldiego@users.noreply.github.com>
…oncatenationLayer

Co-authored-by: mldiego <39501815+mldiego@users.noreply.github.com>
…utLayer, and PixelClassificationLayer

Co-authored-by: mldiego <39501815+mldiego@users.noreply.github.com>
Copilot AI changed the title [WIP] Can you create unit and integration tests for every layer and function in the endine directory? Add comprehensive unit and integration tests for engine/nn layers and functions Oct 3, 2025
Copilot AI requested a review from mldiego October 3, 2025 16:56
mldiego added 17 commits October 3, 2025 14:38
Merging latest changes before copilot tests
Refactor Star initialization by removing unnecessary parameters.
Removed tests for AdditionLayer with ImageZono inputs.
Removed test for ConcatenationLayer with Star inputs.
Removed test case for DepthConcatenationLayer with ImageStar inputs.
Updated assertions for output dimensions in FlattenLayer tests and removed obsolete ImageZono test.
The ones still failing is due to code bugs/errors, will fix those in the future
Removed precision conversion for Max and Min parameters.
mldiego added 24 commits October 3, 2025 16:40
Removed test for DepthConcatenationLayer with ImageZono inputs.
Removed the 'option' parameter from the reach_star_approx method call.
Update dimension retrieval in reach_star_single_input function to use in_set.
Removed tests for HardSigmoidLayer with ImageStar and Star inputs.
Removed assertions for result classes and output type.
Removed test case for ReshapeLayer with -1 in targetDim.
Updated test for SequenceInputLayer to use ImageStar instead of Box.
Commented out assertions and added print statements to check output sizes.
Updated the test for SaturatingLinearSymmLayer to use Star input instead of ImageStar with scaled images.
@mldiego mldiego marked this pull request as ready for review October 14, 2025 10:08
@mldiego mldiego merged commit 7dbf463 into master Oct 14, 2025
1 check passed
@mldiego mldiego deleted the copilot/fix-5595ad52-e646-4345-9f99-f2aab25ff64b branch October 14, 2025 10:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants