22import pytest
33from numpy .testing import assert_almost_equal , assert_equal , assert_raises
44
5- from vrplib .parse .parse_distances import (
6- from_eilon ,
7- from_lower_row ,
8- is_triangular_number ,
9- parse_distances ,
10- )
5+ from vrplib .parse .parse_distances import parse_distances
116
127
138@pytest .mark .parametrize (
@@ -68,33 +63,24 @@ def test_parse_euclidean_distances(edge_weight_type, desired):
6863
6964
7065@pytest .mark .parametrize (
71- "comment, func" , [("Eilon" , from_eilon ), (None , from_lower_row )]
66+ "data" ,
67+ [
68+ [[1 , 2 , 3 , 4 , 5 , 6 ]], # single line
69+ [[1 , 2 , 3 , 4 ], [5 , 6 ]], # ragged lines
70+ [[1 ], [2 , 3 ], [4 , 5 , 6 ]], # proper triangular rows
71+ ],
7272)
73- def test_parse_lower_row (comment , func ):
73+ def test_parse_lower_row (data ):
7474 """
75- Tests if a ``LOWER ROW`` instance is parsed as Eilon instance or regular
76- instance. Eilon instances do not contain a proper lower row matrix, but
77- a lower column matrix instead. The current way of detecting an Eilon
78- instance is by means of the ``COMMENT`` field, which is checked for
79- including "Eilon".
75+ Tests that LOWER_ROW instances are parsed correctly regardless of how
76+ the values are wrapped across lines. See #134.
8077 """
81- instance = {
82- "data" : np .array ([[1 ], [2 , 3 ], [4 , 5 , 6 ]], dtype = object ),
83- "edge_weight_type" : "EXPLICIT" ,
84- "edge_weight_format" : "LOWER_ROW" ,
85- "comment" : comment ,
86- }
87-
88- assert_equal (parse_distances (** instance ), func (instance ["data" ]))
89-
90-
91- def test_from_lower_row ():
92- """
93- Tests that a lower row triangular matrix is correctly transformed into a
94- full matrix.
95- """
96- triangular_matrix = np .array ([[1 ], [2 , 3 ], [4 , 5 , 6 ]], dtype = object )
97- actual = from_lower_row (triangular_matrix )
78+ data = np .array (data , dtype = object )
79+ actual = parse_distances (
80+ data ,
81+ edge_weight_type = "EXPLICIT" ,
82+ edge_weight_format = "LOWER_ROW" ,
83+ )
9884 desired = np .array (
9985 [
10086 [0 , 1 , 2 , 4 ],
@@ -105,31 +91,3 @@ def test_from_lower_row():
10591 )
10692
10793 assert_equal (actual , desired )
108-
109-
110- def test_from_eilon ():
111- """
112- Tests that the distance matrix of Eilon instances is correctly transformed.
113- These distance matrices have entries corresponding to the lower column
114- triangular matrices. But the distance matrix is not a triangular matrix,
115- so they are flattened first.
116- """
117- eilon = np .array ([[1 , 2 , 3 , 4 ], [5 , 6 ]], dtype = object )
118- actual = from_eilon (eilon )
119- desired = np .array (
120- [
121- [0 , 1 , 2 , 3 ],
122- [1 , 0 , 4 , 5 ],
123- [2 , 4 , 0 , 6 ],
124- [3 , 5 , 6 , 0 ],
125- ]
126- )
127-
128- assert_equal (actual , desired )
129-
130-
131- @pytest .mark .parametrize (
132- "n, res" , [(1 , True ), (3 , True ), (4 , False ), (630 , True ), (1000 , False )]
133- )
134- def test_is_triangular_number (n , res ):
135- assert_equal (is_triangular_number (n ), res )
0 commit comments