• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

xaviersolau / QPSolver / 16332377818

16 Jul 2025 11:21PM UTC coverage: 77.815%. First build
16332377818

push

github

xaviersolau
Initial import.

235 of 302 new or added lines in 10 files covered. (77.81%)

235 of 302 relevant lines covered (77.81%)

671207.23 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

66.67
/src/libs/SoloX.QPSolver/Impl/QPProblemValidator.cs
1
// ----------------------------------------------------------------------
2
// <copyright file="QPProblemValidator.cs" company="Xavier Solau">
3
// Copyright © 2025 Xavier Solau.
4
// Licensed under the MIT license.
5
// See LICENSE file in the project root for full license information.
6
// </copyright>
7
// ----------------------------------------------------------------------
8

9
using MathNet.Numerics.LinearAlgebra;
10
using SoloX.QPSolver.Exceptions;
11

12
namespace SoloX.QPSolver.Impl
13
{
14
    internal sealed class QPProblemValidator : IQPProblemConfiguration
15
    {
16
        public int? Size { get; private set; }
17

18
        private bool minimizingConfigured;
19
        private bool lowerBoundsConfigured;
20
        private bool upperBoundsConfigured;
21

22
        public IQPProblemConfiguration Minimizing(Matrix<double> matrixQ, Vector<double> vectorC)
23
        {
24
            if (matrixQ.ColumnCount != matrixQ.RowCount)
3,366✔
25
            {
NEW
26
                throw new QPEngineException("The matrix Q must be a square matrix.");
×
27
            }
28

29
            if (matrixQ.ColumnCount != vectorC.Count)
3,366✔
30
            {
NEW
31
                throw new QPEngineException("The vector c size must be equal to matrix Q columns/rows count.");
×
32
            }
33

34
            if (Size == null)
3,366✔
35
            {
36
                Size = vectorC.Count;
1✔
37
            }
38
            else if (Size != vectorC.Count)
3,365✔
39
            {
NEW
40
                throw new QPEngineException($"The vector c size must be {Size} and the matrix Q must be {Size}x{Size}.");
×
41
            }
42

43
            if (this.minimizingConfigured)
3,366✔
44
            {
NEW
45
                throw new QPEngineException($"Minimizing configuration method already called.");
×
46
            }
47

48
            this.minimizingConfigured = true;
3,366✔
49

50
            return this;
3,366✔
51
        }
52

53
        public IQPProblemConfiguration WithEquality(Matrix<double> matrixAEquality, Vector<double> vectorBEquality)
54
        {
55
            if (matrixAEquality.RowCount != vectorBEquality.Count)
1,124✔
56
            {
NEW
57
                throw new QPEngineException($"The matrix Aeq row count must be equal to the vector beq size.");
×
58
            }
59

60
            if (Size == null)
1,124✔
61
            {
62
                Size = matrixAEquality.ColumnCount;
1,123✔
63
            }
64
            else if (Size != matrixAEquality.ColumnCount)
1✔
65
            {
NEW
66
                throw new QPEngineException($"The matrix Aeq must have {Size} columns.");
×
67
            }
68

69
            return this;
1,124✔
70
        }
71

72
        public IQPProblemConfiguration WithInequality(Matrix<double> matrixAInequality, Vector<double> vectorBInequality)
73
        {
74
            if (matrixAInequality.RowCount != vectorBInequality.Count)
1,122✔
75
            {
NEW
76
                throw new QPEngineException($"The matrix Aineq row count must be equal to the vector bineq size.");
×
77
            }
78

79
            if (Size == null)
1,122✔
80
            {
81
                Size = matrixAInequality.ColumnCount;
1,122✔
82
            }
NEW
83
            else if (Size != matrixAInequality.ColumnCount)
×
84
            {
NEW
85
                throw new QPEngineException($"The matrix Aineq must have {Size} columns.");
×
86
            }
87

88
            return this;
1,122✔
89
        }
90

91
        public IQPProblemConfiguration WithLowerBounds(Vector<double> lowerBounds)
92
        {
93
            if (Size == null)
1,122✔
94
            {
95
                Size = lowerBounds.Count;
1,120✔
96
            }
97
            else if (Size != lowerBounds.Count)
2✔
98
            {
NEW
99
                throw new QPEngineException($"The lower bound must have {Size} size.");
×
100
            }
101

102
            if (this.lowerBoundsConfigured)
1,122✔
103
            {
NEW
104
                throw new QPEngineException($"WithLowerBounds configuration method already called.");
×
105
            }
106

107
            this.lowerBoundsConfigured = true;
1,122✔
108

109
            return this;
1,122✔
110
        }
111

112
        public IQPProblemConfiguration WithUpperBounds(Vector<double> upperBounds)
113
        {
114
            if (Size == null)
1,121✔
115
            {
NEW
116
                Size = upperBounds.Count;
×
117
            }
118
            else if (Size != upperBounds.Count)
1,121✔
119
            {
NEW
120
                throw new QPEngineException($"The upper bound must have {Size} size.");
×
121
            }
122

123
            if (this.upperBoundsConfigured)
1,121✔
124
            {
NEW
125
                throw new QPEngineException($"WithUpperBounds configuration method already called.");
×
126
            }
127

128
            this.upperBoundsConfigured = true;
1,121✔
129

130
            return this;
1,121✔
131
        }
132
    }
133
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc