|
| 1 | +import munit.Assertions as A |
| 2 | + |
| 3 | +import org.expr.mcdm.waspas |
| 4 | +import org.expr.mcdm.Direction.{Maximize, Minimize} |
| 5 | +import org.expr.mcdm.Matrix |
| 6 | + |
| 7 | +class TestWaspas extends munit.FunSuite { |
| 8 | + test("Waspas Example - 1") { |
| 9 | + val decmat = Array( |
| 10 | + Array(3.0, 12.5, 2, 120, 14, 3), |
| 11 | + Array(5.0, 15, 3, 110, 38, 4), |
| 12 | + Array(3.0, 13, 2, 120, 19, 3), |
| 13 | + Array(4.0, 14, 2, 100, 31, 4), |
| 14 | + Array(3.0, 15, 1.5, 125, 40, 4) |
| 15 | + ) |
| 16 | + |
| 17 | + val weights = Array(0.221, 0.159, 0.175, 0.127, 0.117, 0.201) |
| 18 | + |
| 19 | + val fns = Array(Maximize, Minimize, Minimize, Maximize, Minimize, Maximize) |
| 20 | + |
| 21 | + val result = waspas(decmat, weights, fns) |
| 22 | + |
| 23 | + val expectedScores = Array(0.805021, 0.775060, 0.770181, 0.796424, 0.788239) |
| 24 | + |
| 25 | + val expectedNormalizedMatrix = Array( |
| 26 | + Array(0.6, 1.0, 0.75, 0.96, 1.0, 0.75), |
| 27 | + Array(1.0, 0.833333, 0.5, 0.88, 0.368421, 1.0), |
| 28 | + Array(0.6, 0.961538, 0.75, 0.96, 0.736842, 0.75), |
| 29 | + Array(0.8, 0.892857, 0.75, 0.8, 0.451613, 1.0), |
| 30 | + Array(0.6, 0.833333, 1.0, 1.0, 0.35, 1.0) |
| 31 | + ) |
| 32 | + |
| 33 | + val expectedScoresWSM = Array( |
| 34 | + 0.8125199999999999, |
| 35 | + 0.7968652631578947, |
| 36 | + 0.7756151417004049, |
| 37 | + 0.8054529953917051, |
| 38 | + 0.80905) |
| 39 | + |
| 40 | + val expectedScoresWPM = Array( |
| 41 | + 0.7975224331331252, |
| 42 | + 0.7532541470584717, |
| 43 | + 0.7647463553356331, |
| 44 | + 0.7873956894790834, |
| 45 | + 0.7674278741781709) |
| 46 | + |
| 47 | + A.assert(Matrix.elementwise_equal(result.normalizedDecisionMatrix, expectedNormalizedMatrix, 1e-5)) |
| 48 | + |
| 49 | + A.assert(Matrix.elementwise_equal(result.scoresWSM, expectedScoresWSM, 1e-5)) |
| 50 | + |
| 51 | + A.assert(Matrix.elementwise_equal(result.scoresWPM, expectedScoresWPM, 1e-5)) |
| 52 | + |
| 53 | + A.assert(Matrix.elementwise_equal(result.scores, expectedScores, 1e-5)) |
| 54 | + |
| 55 | + } |
| 56 | +} |
0 commit comments