Task 4 — Generic Pipeline Stability Analysis
Objective
Create a function named:
ReportForInvalidPipelines(...)
that analyzes multiple numeric pipelines.
The function must support two numeric forms:
integer
float32
Every pipeline has its own stability level.
For every value below the stability level, report:
- the value
- the required stability level
- how far below the stability level the value is
- the pipeline from which the value originated
Integer Form
Example:
pipelines := [][]int{
{
72, 55, 63, 48, 91,
34, 25, 81, 60, 19,
42, 88, 77, 93, 69,
18, 57, 36, 41, 84,
},
{
54, 73, 29, 92, 68,
15, 84, 59, 67, 21,
39, 64, 98, 41, 26,
18, 33, 51, 72, 80,
},
}
Stability levels:
stability := []int{
50,
65,
}
The relationship is:
pipelines[0] -> stability[0] = 50
pipelines[1] -> stability[1] = 65
Float Form
Example:
pipelines := [][]float32{
{
10.51, 98.74, 56.35, 81.26, 67.88,
49.57, 26.14, 12.77, 94.31, 38.90,
},
{
53.14, 29.82, 61.47, 74.56, 85.73,
10.12, 77.64, 58.92, 34.91, 69.78,
},
}
Stability levels:
stability := []float32{
50.50,
65.75,
}
Stability Rule
For pipeline i:
threshold = stability[i]
A value is invalid when:
value < threshold
A value equal to the threshold is stable.
Difference
For every invalid value:
difference = threshold - value
The result must therefore always be positive.
Suggested Result Model
Conceptually:
type InvalidPipelineValue[T Number] struct {
PipelineIndex int
Value T
Stability T
Difference T
}
and:
type PipelineReport[T Number] struct {
AnalysisType string
Invalid []InvalidPipelineValue[T]
}
The exact generic syntax depends on the implementation language.
Go Implementation Options
In Go, this may be solved using:
- generics
- two typed wrappers around shared logic
- another explicitly typed abstraction
The implementation should avoid an unnecessarily weak interface{} result when a type-safe solution is possible.
Integer Example
For the first integer pipeline:
stability = 50
values such as:
48
34
25
19
42
18
36
41
are below the stability level.
For:
value = 48
the deficit is:
50 - 48 = 2
For:
value = 25
the deficit is:
50 - 25 = 25
Float Example
For the first float pipeline:
stability = 50.50
a value such as:
49.57
has deficit:
50.50 - 49.57 = 0.93
Floating-point presentation may require formatting, but comparisons should use the numeric values rather than formatted strings.
Input Relationship
There must be exactly one stability value for every pipeline.
Therefore:
len(pipelines) == len(stability)
must hold.
Otherwise the input configuration is invalid.
Analysis Type
The original task requires information about the “type of analysis” and mentions distinguishing whether a 1D or 2D slice is being analyzed.
However, both provided function forms use a two-dimensional first argument:
[][]int
[][]float32
Therefore, the original source does not fully define what “1D or 2D analysis” means in this context.
Do not invent additional 1D behavior without extending the specification.
At minimum, the report should identify the numeric form being analyzed, for example:
integer pipelines
or:
float32 pipelines
If support for true 1D input is later added, it should be documented as a separate extension.
Requirements
The function must:
- support integer pipeline analysis
- support float32 pipeline analysis
- associate each pipeline with its stability level
- find every value below the threshold
- calculate the deficit
- report the source pipeline
- identify the analysis form
- validate input relationships
Testing
Create multiple tests.
At minimum:
- integer example
- float32 example
- all values stable
- all values unstable
- value exactly equal to stability
- mismatched number of pipelines and stability values
- empty input
- floating-point boundary case
Implementation Notes
The core algorithm is identical for both numeric forms:
for each pipeline
↓
resolve its threshold
↓
for each value
↓
if value < threshold
↓
calculate deficit
↓
add report entry
The numeric type changes, but the processing model does not.