forked from glojurelang/glojure
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix sort fails for lists and vectors (glojurelang#66)
- Loading branch information
Showing
12 changed files
with
109 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
package lang | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
) | ||
|
||
func Compare(a, b any) int { | ||
if s1, ok := a.(string); ok { | ||
if s2, ok := b.(string); ok { | ||
return strings.Compare(s1, s2) | ||
} | ||
panic(NewIllegalArgumentError(fmt.Sprintf("cannot compare unrelated types: %T, %T", a, b))) | ||
} else if i1, ok := a.(int); ok { | ||
if i2, ok := b.(int); ok { | ||
if i1 > i2 { | ||
return 1 | ||
} | ||
if i1 < i2 { | ||
return -1 | ||
} | ||
return 0 | ||
} | ||
panic(NewIllegalArgumentError(fmt.Sprintf("cannot compare unrelated types: %T, %T", a, b))) | ||
} else if i1, ok := a.(int32); ok { | ||
if i2, ok := b.(int32); ok { | ||
if i1 > i2 { | ||
return 1 | ||
} | ||
if i1 < i2 { | ||
return -1 | ||
} | ||
return 0 | ||
} | ||
panic(NewIllegalArgumentError(fmt.Sprintf("cannot compare unrelated types: %T, %T", a, b))) | ||
} else if i1, ok := a.(int64); ok { | ||
if i2, ok := b.(int64); ok { | ||
if i1 > i2 { | ||
return 1 | ||
} | ||
if i1 < i2 { | ||
return -1 | ||
} | ||
return 0 | ||
} | ||
panic(NewIllegalArgumentError(fmt.Sprintf("cannot compare unrelated types: %T, %T", a, b))) | ||
} else if i1, ok := a.(float32); ok { | ||
if i2, ok := b.(float32); ok { | ||
if i1 > i2 { | ||
return 1 | ||
} | ||
if i1 < i2 { | ||
return -1 | ||
} | ||
return 0 | ||
} | ||
panic(NewIllegalArgumentError(fmt.Sprintf("cannot compare unrelated types: %T, %T", a, b))) | ||
} else if i1, ok := a.(float64); ok { | ||
if i2, ok := b.(float64); ok { | ||
if i1 > i2 { | ||
return 1 | ||
} | ||
if i1 < i2 { | ||
return -1 | ||
} | ||
return 0 | ||
} | ||
panic(NewIllegalArgumentError(fmt.Sprintf("cannot compare unrelated types: %T, %T", a, b))) | ||
} | ||
|
||
panic(NewIllegalArgumentError(fmt.Sprintf("unable to compare types: %T, %T", a, b))) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
(ns glojure.test-glojure.sort | ||
(:use glojure.test)) | ||
|
||
(deftest Sort-Vector | ||
(is (= [1 2 3] (sort [1 3 2])))) | ||
|
||
(deftest Sort-Arrays | ||
(is (= '(1 2 3) (sort '(1 3 2))))) |