|
| 1 | +import munit.Assertions as A |
| 2 | + |
| 3 | +import org.expr.mcdm.lmaw |
| 4 | +import org.expr.mcdm.Direction.{Maximize, Minimize} |
| 5 | +import org.expr.mcdm.Matrix |
| 6 | + |
| 7 | +class TestLmaw extends munit.FunSuite { |
| 8 | + test("LMAW Example - 1") { |
| 9 | + |
| 10 | + val decmat = Array( |
| 11 | + Array(647.34, 6.24, 49.87, 19.46, 212.58, 6.75), |
| 12 | + Array(115.64, 3.24, 16.26, 9.69, 207.59, 3.00), |
| 13 | + Array(373.61, 5.00, 26.43, 12.00, 184.62, 3.74), |
| 14 | + Array(37.63, 2.48, 2.85, 9.25, 142.50, 3.24), |
| 15 | + Array(858.01, 4.74, 62.85, 45.96, 267.95, 4.00), |
| 16 | + Array(222.92, 3.00, 19.24, 21.46, 221.38, 3.49) |
| 17 | + ) |
| 18 | + |
| 19 | + val weights = Array(0.215, 0.126, 0.152, 0.091, 0.19, 0.226) |
| 20 | + |
| 21 | + val fns = Array(Maximize, Maximize, Minimize, Minimize, Minimize, Maximize) |
| 22 | + |
| 23 | + val result = lmaw(decmat, weights, fns) |
| 24 | + |
| 25 | + val expected_scores = Array(4.839005264308832, 4.679718180594332, |
| 26 | + 4.797731427991642, 4.732145373983716, 4.73416833375772, 4.702247270959649) |
| 27 | + |
| 28 | + val expected_best_index = 0 |
| 29 | + |
| 30 | + A.assert(Matrix.elementwise_equal(result.scores, expected_scores, 1e-6), |
| 31 | + s"Expected scores: ${Matrix.prettyPrint(expected_scores)} but got: ${Matrix.prettyPrint(result.scores)}") |
| 32 | + A.assertEquals(result.best, expected_best_index, |
| 33 | + s"Expected best index: $expected_best_index but got: ${result.best}") |
| 34 | + } |
| 35 | +} |
0 commit comments