Skip to content

Commit

Permalink
Merge pull request moonbitlang#419 from moonbitlang/hongbo/tweak3
Browse files Browse the repository at this point in the history
clean up
  • Loading branch information
bobzhang authored May 21, 2024
2 parents 648d464 + ee20a9f commit 6ea7410
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 42 deletions.
1 change: 0 additions & 1 deletion fixedarray/fixedarray.mbti
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ fn new[T](Int, () -> T) -> FixedArray[T]
fn new_with_index[T](Int, (Int) -> T) -> FixedArray[T]

// Types and methods
type TimSortRun
impl FixedArray {
all[T](Self[T], (T) -> Bool) -> Bool
any[T](Self[T], (T) -> Bool) -> Bool
Expand Down
2 changes: 1 addition & 1 deletion fixedarray/sort.mbt
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ pub fn stable_sort[T : Compare](self : FixedArray[T]) -> Unit {
timsort({ array: self, start: 0, end: self.length() })
}

struct TimSortRun {
priv struct TimSortRun {
len : Int
start : Int
}
Expand Down
68 changes: 28 additions & 40 deletions hashmap/hashmap_test.mbt
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,13 @@ impl Show for MyString with to_string(self) { self.0 }

test "set" {
let m : HashMap[MyString, Int] = HashMap::new()
fn i(s) {
MyString::MyString(s)
}

m.set("a" |> i, 1)
m.set("b" |> i, 1)
m.set("bc" |> i, 2)
m.set("abc" |> i, 3)
m.set("cd" |> i, 2)
m.set("c" |> i, 1)
m.set("d" |> i, 1)
m.set("a", 1)
m.set("b", 1)
m.set("bc", 2)
m.set("abc", 3)
m.set("cd", 2)
m.set("c", 1)
m.set("d", 1)
@assertion.assert_eq(m.size, 7)?
inspect(
m.debug_entries(),
Expand Down Expand Up @@ -108,17 +104,13 @@ test "from_array" {

test "remove" {
let m : HashMap[MyString, Int] = HashMap::new()
fn i(s) {
MyString::MyString(s)
}

m.set("a" |> i, 1)
m.set("ab" |> i, 2)
m.set("bc" |> i, 2)
m.set("cd" |> i, 2)
m.set("abc" |> i, 3)
m.set("abcdef" |> i, 6)
m.remove("ab" |> i)
m.set("a", 1)
m.set("ab", 2)
m.set("bc", 2)
m.set("cd", 2)
m.set("abc", 3)
m.set("abcdef", 6)
m.remove("ab")
@assertion.assert_eq(m.size(), 5)?
inspect(
m.debug_entries(),
Expand All @@ -128,14 +120,10 @@ test "remove" {

test "remove_unexist_key" {
let m : HashMap[MyString, Int] = HashMap::new()
fn i(s) {
MyString::MyString(s)
}

m.set("a" |> i, 1)
m.set("ab" |> i, 2)
m.set("abc" |> i, 3)
m.remove("d" |> i)
m.set("a", 1)
m.set("ab", 2)
m.set("abc", 3)
m.remove("d")
@assertion.assert_eq(m.size(), 3)?
inspect(m.debug_entries(), content="_,(0,a,1),(0,ab,2),(0,abc,3),_,_,_,_")?
}
Expand Down Expand Up @@ -193,20 +181,20 @@ test "grow" {
MyString::MyString(s)
}

m.set("C" |> i, 1)
m.set("Go" |> i, 2)
m.set("C++" |> i, 3)
m.set("Java" |> i, 4)
m.set("Scala" |> i, 5)
m.set("Julia" |> i, 5)
m.set("C", 1)
m.set("Go", 2)
m.set("C++", 3)
m.set("Java", 4)
m.set("Scala", 5)
m.set("Julia", 5)
@assertion.assert_eq(m.size, 6)?
@assertion.assert_eq(m.capacity, 8)?
m.set("Cobol" |> i, 5)
m.set("Cobol", 5)
@assertion.assert_eq(m.size, 7)?
@assertion.assert_eq(m.capacity, 16)?
m.set("Python" |> i, 6)
m.set("Haskell" |> i, 7)
m.set("Rescript" |> i, 8)
m.set("Python", 6)
m.set("Haskell", 7)
m.set("Rescript", 8)
@assertion.assert_eq(m.size, 10)?
@assertion.assert_eq(m.capacity, 16)?
inspect(
Expand Down

0 comments on commit 6ea7410

Please sign in to comment.