Files
DP44/docs/ai/Common/DTS.Common.Tests.md
2026-04-17 14:55:32 -04:00

7.3 KiB

source_files, generated_at, model, schema_version, sha256
source_files generated_at model schema_version sha256
Common/DTS.Common.Tests/ChannelTypeUtilityShould.cs
Common/DTS.Common.Tests/NetworkUtilsShould.cs
Common/DTS.Common.Tests/LinearizationFormulaShould.cs
Common/DTS.Common.Tests/GroupChannelShould.cs
Common/DTS.Common.Tests/FilterClassShould.cs
2026-04-17T15:36:48.677576+00:00 zai-org/GLM-5-FP8 1 ea00a32036ad9490

DTS.Common.Tests Module Documentation

1. Purpose

This module contains unit tests for the DTS.Common library, which provides core utility classes and data structures for sensor configuration, network connection handling, signal linearization, and filter class management. The tests validate parsing logic, mathematical transformations, and mapping behaviors for sensor-related domain concepts including channel types, network connection strings, linearization formulas, and ISO-compliant filter classifications.


2. Public Interface

The following classes and methods are under test (the actual production interfaces being validated):

ChannelTypeUtility (inferred from DTS.Common.Classes.Sensors)

  • static string ParseSensorKnownChannelType(string sensorName) - Parses a sensor name string to extract a known channel type tag. Returns the channel type as a string matching a KnownChannelTypes enum value, or an empty string if parsing fails.

NetworkUtils (inferred from DTS.Common.Utils)

  • static bool TryParseConnectionString(string connectionString, out string ipAddress) - Attempts to extract an IP address from a connection string. Returns true and populates ipAddress if successful; returns false otherwise. Handles formats: bare IP, IP:port, and protocol-prefixed URLs (e.g., udp://, http://).

LinearizationFormula (inferred from DTS.Common.Classes.Sensors)

  • double GetLinearizedValue(double input, int coefficientCount, bool? isProportional) - Computes a linearized engineering unit value using polynomial coefficients. The isProportional parameter affects the calculation behavior.
  • double[] PolynomialCoefficients - Property containing the polynomial coefficients for linearization.
  • NonLinearStyles NonLinearStyle - Property indicating the linearization style; defaults to NonLinearStyles.Polynomial.

GroupChannel (inferred from DTS.Common.Classes.Groups)

  • GroupChannel(bool flag, string groupName, IGroup group, IChannelSetting[] settings) - Constructor accepting a boolean flag, group name, group interface, and channel settings array.
  • FilterClass GetFilterClassFromISOCode(ISoftwareFilter[] filters, string isoCodeString) - Maps an ISO code (extracted from position 15 of the input string) to a FilterClass object containing FClass and Frequency properties.

FilterClass (inferred from DTS.Common.Classes.Sensors)

  • static FilterClass GetFilterClassFromString(string filterString) - Parses a filter class string (e.g., "CFC 1000", "1700Hz", "None") into a FilterClass object.
  • static FilterClass GetDefaultFilterClass(List<ISoftwareFilter> softwareFilters) - Returns the default filter class by examining the IsDefault property on each ISoftwareFilter in the list.
  • static double GetFrequencyFromFilterClassType(FilterClassType filterClassType) - Returns the associated frequency for a given FilterClassType.
  • FilterClassType FClass - Property indicating the filter class type.
  • double Frequency - Property indicating the filter frequency in Hz.

3. Invariants

ChannelTypeUtility

  • ParseSensorKnownChannelType always returns a non-null string (empty string on failure).
  • Valid channel type prefixes are exactly 2 characters and must match a KnownChannelTypes enum value.
  • Input strings shorter than 2 characters always return empty string.

NetworkUtils

  • TryParseConnectionString returns false for null input without throwing.
  • USB device paths (format \\?\usb#...) are not parsed as IP addresses.
  • Protocol prefixes (udp://, http://) are stripped before IP extraction.
  • Port numbers are stripped from the output ipAddress.

LinearizationFormula

  • NonLinearStyle defaults to NonLinearStyles.Polynomial when not explicitly set.
  • isProportional values of true and null produce equivalent (non-proportional) behavior based on test assertions.

GroupChannel

  • ISO code is extracted from character index 15 (16th character) of the input string.
  • Unknown ISO codes default to FilterClassType.CFC1000.

FilterClass

  • GetFilterClassFromString returns FilterClassType.Unfiltered for null, empty, or invalid inputs.
  • GetDefaultFilterClass returns FilterClassType.CFC1000 when the input list is null or empty.
  • GetFrequencyFromFilterClassType throws Exception for FilterClassType.AdHoc (AdHoc filters require explicit frequency).

ISO Code to FilterClassType Mapping

ISO Code FilterClassType Frequency
'A' CFC1000 1650 Hz
'B' CFC600 1000 Hz
'C' CFC180 300 Hz
'D' CFC60 100 Hz
'0' Unfiltered -2
'P' None 0
'S' AdHoc Variable (from filter)

4. Dependencies

This module depends on:

  • NUnit.Framework - Testing framework for assertions and test attributes.
  • NSubstitute - Mocking library for interface substitution.
  • DTS.Common.Classes.Sensors - Contains ChannelTypeUtility, LinearizationFormula, FilterClass, KnownChannelTypes.
  • DTS.Common.Utils - Contains NetworkUtils.
  • DTS.Common.Enums.Sensors - Contains FilterClassType, NonLinearStyles.
  • DTS.Common.Interface.Sensors - Contains ISoftwareFilter.
  • DTS.Common.Interface.Channels - Contains IChannelSetting.
  • DTS.Common.Interface.Groups.GroupList - Contains IGroup.

What depends on this module:

  • This is a test project; no production code depends on it.

5. Gotchas

  1. Typo in test method name: ParseSensorKnownChannelType_ShouldRetuenEmpty_WhenPassedNull (and similar methods) misspells "Return" as "Retuen". This is a naming issue only but may cause confusion when searching for test methods.

  2. Missing [Test] attribute: The method GetFilterClassFromISOCode_ShouldReturnNoneWhenIsoIsP in GroupChannelShould.cs lacks a [Test] attribute and will not execute as a test.

  3. ISO code position assumption: GetFilterClassFromISOCode assumes the ISO code is always at index 15 of the input string. The test uses "???????????????X" patterns (15 question marks + code) to validate this, but the source does not document what the preceding characters represent.

  4. AdHoc frequency exception: Calling GetFrequencyFromFilterClassType(FilterClassType.AdHoc) throws an exception. Consumers must handle AdHoc filters separately by reading the Frequency property directly.

  5. Unfiltered frequency value: FilterClassType.Unfiltered maps to frequency -2, not 0. This is a sentinel value and may affect logic that assumes non-negative frequencies.

  6. Proportional flag behavior: The test GetLinearizedValue_ShouldReturnCorrectEU_OnNonLinearAndProportionalSpecifiedAsNull indicates that null and true for the isProportional parameter produce the same result, which is counterintuitive. The expected behavior for null vs true vs false is not clearly documented in the tests.