Skip to content

Commit

Permalink
Fix bug in List.Sorted when List contains non-dyadic rationals (#51)
Browse files Browse the repository at this point in the history
Fixes a bug in List.Sorted when the list contains non-dyadic rationals. For example:

`[92/47, 41/23, 9/4, 3].Sorted`
  • Loading branch information
aaron-siegel committed Dec 23, 2023
1 parent f9e3bb1 commit 0201b7f
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package org.cgsuite.lang

import org.cgsuite.core.CanonicalShortGame
import org.cgsuite.core.{CanonicalShortGame, RationalNumber}
import org.cgsuite.core.misere.MisereCanonicalGame
import org.cgsuite.util.Coordinates

Expand All @@ -12,6 +12,7 @@ object UniversalOrdering extends Ordering[Any] {
case (null, null) => 0
case (null, _) => -1
case (_, null) => 1
case (x: RationalNumber, y: RationalNumber) => x compare y // This is consistent with CanonicalShortGame.DeterministicOrdering
case (g: CanonicalShortGame, h: CanonicalShortGame) => CanonicalShortGame.DeterministicOrdering.compare(g, h)
case (_: CanonicalShortGame, _) => -1
case (_, _: CanonicalShortGame) => 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ class CgsuiteLangTest extends CgscriptSpec {
|--+---+--
|9""".stripMargin),
("List: Sorted", "[[5,3,7],[1,6,3],[9,2,8]].Sorted", "[[1,6,3],[5,3,7],[9,2,8]]"),
("List: Sorted with non-dyadic rationals", "[92/47, 41/23, 9/4, 3].Sorted", "[41/23,92/47,9/4,3]"),
("List: SortedWith", "[[5,3,7],[1,6,3],[9,2,8]].SortedWith((a, b) -> a[2] - b[2])", "[[9,2,8],[5,3,7],[1,6,3]]"),
("List: SortedWith invalid comparator", "[[5,3,7],[1,6,3],[9,2,8]].SortedWith((a, b) -> \"I am a banana.\")",
"!!Expected `game.Integer`; found `cgsuite.lang.String`."),
Expand Down

0 comments on commit 0201b7f

Please sign in to comment.