Skip to content

Commit 9cc1a78

Browse files
Improve code coverage
1 parent ace62d1 commit 9cc1a78

File tree

3 files changed

+57
-24
lines changed

3 files changed

+57
-24
lines changed

Diff for: src/expressions.lisp

-5
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,6 @@
2424
(declaim (inline sum-linear-expressions))
2525
(defun sum-linear-expressions (&rest exprs)
2626
"Takes linear expressions and reduces it into a single expression."
27-
(sum-linear-expressions-list exprs))
28-
29-
(declaim (inline sum-linear-expressions-list))
30-
(defun sum-linear-expressions-list (exprs)
31-
"Takes a list of linear expressions and reduces it into a single expression."
3227
(let ((sum (copy-alist (first exprs))))
3328
(iter (for expr in (rest exprs))
3429
(iter (for term in expr)

Diff for: t/expressions.lisp

+14
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,20 @@
1515
:description "The suite to test linear-programming/expressions")
1616
(in-suite expressions)
1717

18+
(test linear-constant-p
19+
(declare (notinline linear-programming/expressions::linear-constant-p))
20+
(is-true (linear-programming/expressions::linear-constant-p
21+
(parse-linear-expression 5)))
22+
(is-true (linear-programming/expressions::linear-constant-p
23+
(parse-linear-expression 2/3)))
24+
(is-true (linear-programming/expressions::linear-constant-p
25+
(parse-linear-expression -1.0)))
26+
27+
(is-false (linear-programming/expressions::linear-constant-p
28+
(parse-linear-expression 'x)))
29+
(is-false (linear-programming/expressions::linear-constant-p
30+
(parse-linear-expression '(+ x 5)))))
31+
1832
(test scale-linear-expression
1933
(declare (notinline scale-linear-expression))
2034
(is (equal '((a . 24) (b . 7/2) (c . 4.5))

Diff for: t/external-formats.lisp

+43-19
Original file line numberDiff line numberDiff line change
@@ -245,26 +245,50 @@
245245
(is (set-equal '((z . (0 . 4)) (|w| . (0 . 1)) (x . (nil . nil)))
246246
(problem-var-bounds problem)))
247247
(is (simple-linear-constraint-set-equal '((<= ((x . 3) (y . 1)) 8) (<= ((y . 1) (z . 2)) 10) (<= ((|w| . -1) (x . -2) (z . 1)) 1))
248-
(problem-constraints problem))
248+
(problem-constraints problem)))))
249249

250-
(with-open-file (stream (merge-pathnames "t/data/simple-problem-crlf.mps"
251-
(asdf:system-source-directory :linear-programming-test))
252-
:direction :input
253-
:external-format :utf-8)
254-
(let ((problem (read-mps stream 'max)))
255-
(is (typep problem 'problem))
256-
(is (eq 'max (problem-type problem)))
257-
(is-true (null (symbol-package (problem-objective-var problem))))
258-
(is (set-equal '(x y z)
259-
(map 'list #'identity (problem-vars problem))))
260-
(is (set-equal '((x . 1) (y . 4) (z . 8))
261-
(problem-objective-func problem)))
262-
(is (set-equal '()
263-
(problem-integer-vars problem)))
264-
(is (set-equal '()
265-
(problem-var-bounds problem)))
266-
(is (simple-linear-constraint-set-equal '((<= ((x . 3) (y . 1)) 8) (<= ((y . 1) (z . 2)) 7))
267-
(problem-constraints problem)))))))))
250+
; Test input modes
251+
(with-open-file (stream (merge-pathnames "t/data/advanced-problem.mps"
252+
(asdf:system-source-directory :linear-programming-test))
253+
:direction :input
254+
:external-format :utf-8)
255+
(let ((problem (read-mps stream nil :read-case :upcase :rhs-id "rhs1")))
256+
(is (set-equal '(|W| |X| |Y| |Z|)
257+
(map 'list #'identity (problem-vars problem))))))
258+
(with-open-file (stream (merge-pathnames "t/data/advanced-problem.mps"
259+
(asdf:system-source-directory :linear-programming-test))
260+
:direction :input
261+
:external-format :utf-8)
262+
(let ((problem (read-mps stream nil :read-case :downcase :rhs-id "rhs1")))
263+
(is (set-equal '(|w| |x| |y| |z|)
264+
(map 'list #'identity (problem-vars problem))))))
265+
(with-open-file (stream (merge-pathnames "t/data/advanced-problem.mps"
266+
(asdf:system-source-directory :linear-programming-test))
267+
:direction :input
268+
:external-format :utf-8)
269+
(let ((problem (read-mps stream nil :read-case :invert :rhs-id "rhs1")))
270+
(is (set-equal '(|W| |x| |y| |z|)
271+
(map 'list #'identity (problem-vars problem))))))
272+
273+
; Test windows line endings
274+
(with-open-file (stream (merge-pathnames "t/data/simple-problem-crlf.mps"
275+
(asdf:system-source-directory :linear-programming-test))
276+
:direction :input
277+
:external-format :utf-8)
278+
(let ((problem (read-mps stream 'max)))
279+
(is (typep problem 'problem))
280+
(is (eq 'max (problem-type problem)))
281+
(is-true (null (symbol-package (problem-objective-var problem))))
282+
(is (set-equal '(x y z)
283+
(map 'list #'identity (problem-vars problem))))
284+
(is (set-equal '((x . 1) (y . 4) (z . 8))
285+
(problem-objective-func problem)))
286+
(is (set-equal '()
287+
(problem-integer-vars problem)))
288+
(is (set-equal '()
289+
(problem-var-bounds problem)))
290+
(is (simple-linear-constraint-set-equal '((<= ((x . 3) (y . 1)) 8) (<= ((y . 1) (z . 2)) 7))
291+
(problem-constraints problem))))))
268292

269293
(test write-standard-format
270294
(let* ((problem (make-linear-problem (max (+ x y)) (<= (+ (* 2 x) y) 5)))

0 commit comments

Comments
 (0)