Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/fable-library-py/fable_library/MutableMap.fs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ type MutableMap<'Key, 'Value when 'Key: equality>
match this.TryFindIndex(k) with
| true, h, i when i > -1 ->
hashMap.[h].RemoveAt(i)

if hashMap.[h].Count = 0 then
hashMap.Remove(h) |> ignore

true
| _, _, _ -> false

Expand Down
4 changes: 4 additions & 0 deletions src/fable-library-py/fable_library/MutableSet.fs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ type MutableSet<'T when 'T: equality>(items: 'T seq, comparer: IEqualityComparer
match this.TryFindIndex(k) with
| true, h, i when i > -1 ->
hashMap.[h].RemoveAt(i)

if hashMap.[h].Count = 0 then
hashMap.Remove(h) |> ignore

true
| _, _, _ -> false

Expand Down
4 changes: 4 additions & 0 deletions src/fable-library-ts/MutableMap.fs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ type MutableMap<'Key, 'Value when 'Key: equality>
match this.TryFindIndex(k) with
| true, h, i when i > -1 ->
hashMap.[h].RemoveAt(i)

if hashMap.[h].Count = 0 then
hashMap.Remove(h) |> ignore

true
| _, _, _ -> false

Expand Down
4 changes: 4 additions & 0 deletions src/fable-library-ts/MutableSet.fs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ type MutableSet<'T when 'T: equality>(items: 'T seq, comparer: IEqualityComparer
match this.TryFindIndex(k) with
| true, h, i when i > -1 ->
hashMap.[h].RemoveAt(i)

if hashMap.[h].Count = 0 then
hashMap.Remove(h) |> ignore

true
| _, _, _ -> false

Expand Down
24 changes: 24 additions & 0 deletions tests/Beam/DictionaryTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ open System.Collections.Generic
open Fable.Tests.Util
open Util.Testing

type MyRecord = { a: int }

// --- Construction ---

[<Fact>]
Expand Down Expand Up @@ -74,6 +76,28 @@ let ``test Dictionary.Remove works`` () =
dic.Remove("C") |> equal false
dic.Count |> equal 1

[<Fact>]
let ``test Dictionary.Remove with complex keys works`` () =
let dic = Dictionary<_, _>()
dic.Add((0,"A"), "Hello")
dic.Add((1,"B"), "World!")
dic.Remove((0,"A")) |> equal true
dic.Remove((1,"B")) |> equal true
dic.Count |> equal 0

[<Fact>]
let ``test Dictionary.Remove with records as keys works`` () =
let x1 = { a = 5 }
let x2 = { a = 5 }
let x3 = { a = 10 }
let x4 = { a = 15 }
let dict = Dictionary<_, _>()
dict.Add(x1, "Hello")
dict.Add(x3, "World!")
dict.Remove(x2) |> equal true
dict.Remove(x4) |> equal false
dict.Count |> equal 1

// --- TryGetValue ---

[<Fact>]
Expand Down
10 changes: 10 additions & 0 deletions tests/Dart/src/DictionaryTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,15 @@ let tests() =
dic.Add("B", "World!")
dic.Remove("A") |> equal true
dic.Remove("C") |> equal false
dic.Count |> equal 1

testCase "Dictionary.Remove with complex keys works" <| fun () ->
let dic = Dictionary<_, _>()
dic.Add((0,"A"), "Hello")
dic.Add((1,"B"), "World!")
dic.Remove((0,"A")) |> equal true
dic.Remove((1,"B")) |> equal true
dic.Count |> equal 0

testCase "Dictionary.Remove with records as keys works" <| fun () ->
let x1 = { a = 5 }
Expand All @@ -197,6 +206,7 @@ let tests() =
dic.Add(x3, "World!")
dic.Remove(x2) |> equal true
dic.Remove(x4) |> equal false
dic.Count |> equal 1

testCase "Interface IDictionary.Count works" <| fun () ->
let dic = dict <| seq { for i in 1. .. 10. -> i, i*i }
Expand Down
10 changes: 10 additions & 0 deletions tests/Js/Main/DictionaryTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,15 @@ let tests =
dic.Add("B", "World!")
dic.Remove("A") |> equal true
dic.Remove("C") |> equal false
dic.Count |> equal 1

testCase "Dictionary.Remove with complex keys works" <| fun () ->
let dic = Dictionary<_, _>()
dic.Add((0,"A"), "Hello")
dic.Add((1,"B"), "World!")
dic.Remove((0,"A")) |> equal true
dic.Remove((1,"B")) |> equal true
dic.Count |> equal 0

testCase "Dictionary.Remove with records as keys works" <| fun () ->
let x1 = { a = 5 }
Expand All @@ -205,6 +214,7 @@ let tests =
dic.Add(x3, "World!")
dic.Remove(x2) |> equal true
dic.Remove(x4) |> equal false
dic.Count |> equal 1

testCase "Interface IDictionary.Count works" <| fun () ->
let dic = dict <| seq { for i in 1. .. 10. -> i.ToString(), i*i }
Expand Down
27 changes: 25 additions & 2 deletions tests/Python/TestDictionary.fs
Original file line number Diff line number Diff line change
Expand Up @@ -226,16 +226,39 @@ let ``test Dictionary.ContainsValue works`` () =
dic.ContainsValue("Everybody!") |> equal false

[<Fact>]
let ``test Dictionary.Delete works`` () =
let ``test Dictionary.Remove works`` () =
let dic = Dictionary<_, _>()
dic.Add("A", "Hello")
dic.Add("B", "World!")
dic.ContainsValue("Hello") |> equal true
dic.Remove("A") |> equal true
dic.ContainsValue("Hello") |> equal false
dic.Count |> equal 1

[<Fact>]
let ``test Dictionary.Delete works with tuples as keys`` () =
let ``test Dictionary.Remove with complex keys works`` () =
let dic = Dictionary<_, _>()
dic.Add((0,"A"), "Hello")
dic.Add((1,"B"), "World!")
dic.Remove((0,"A")) |> equal true
dic.Remove((1,"B")) |> equal true
dic.Count |> equal 0

[<Fact>]
let ``test Dictionary.Remove with records as keys works`` () =
let x1 = { a = 5 }
let x2 = { a = 5 }
let x3 = { a = 10 }
let x4 = { a = 15 }
let dict = Dictionary<_, _>()
dict.Add(x1, "Hello")
dict.Add(x3, "World!")
dict.Remove(x2) |> equal true
dict.Remove(x4) |> equal false
dict.Count |> equal 1

[<Fact>]
let ``test Dictionary.Remove works with tuples as keys`` () =
let my_dict = Dictionary((Map [for i in 0..10 do yield (i,i), sprintf "Number: %i" i]))
my_dict.ContainsKey((0,0)) |> equal true
my_dict.Remove((0,0)) |> equal true
Expand Down
9 changes: 9 additions & 0 deletions tests/Rust/tests/src/DictionaryTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,15 @@ let ``Dictionary.Remove works`` () =
dict.Remove(3) |> equal false
dict.Count |> equal 1

[<Fact>]
let ``Dictionary.Remove with complex keys works`` () =
let dic = Dictionary<_, _>()
dic.Add((0,"A"), "Hello")
dic.Add((1,"B"), "World!")
dic.Remove((0,"A")) |> equal true
dic.Remove((1,"B")) |> equal true
dic.Count |> equal 0

[<Fact>]
let ``Dictionary.Remove with records as keys works`` () =
let x1 = { a = 5 }
Expand Down
Loading