Skip to content

Commit

Permalink
[Tests] fixed EagerVal and added test
Browse files Browse the repository at this point in the history
  • Loading branch information
luithefirst committed Dec 2, 2024
1 parent e8f3c29 commit 3e37064
Showing 1 changed file with 27 additions and 1 deletion.
28 changes: 27 additions & 1 deletion src/Test/FSharp.Data.Adaptive.Tests/AVal.fs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ type EagerVal<'T>(input : aval<'T>) =
let mutable last = None

override x.MarkObject() =
let v = input.GetValue AdaptiveToken.Top
let v = input.GetValue (AdaptiveToken(x))
match last with
| Some old when DefaultEquality.equals old v ->
printfn "shortcut %A" v
Expand Down Expand Up @@ -189,6 +189,32 @@ let ``[AVal] eager evaluation`` () =
eager |> AVal.force |> should equal "b"
eager.Level |> should be (greaterThan different.Level)


[<Test>]
let ``[AVal] eager marking`` () =
let a = AVal.init 0
let mod2 = a |> AVal.map (fun v -> v % 2)
let eager = EagerVal(mod2) :> aval<_>
let output = eager |> AVal.map id

output |> AVal.force |> should equal 0

transact (fun () -> a.Value <- 2)
output.OutOfDate |> should be False
output |> AVal.force |> should equal 0

transact (fun () -> a.Value <- 1)
output.OutOfDate |> should be True
output |> AVal.force |> should equal 1

transact (fun () -> a.Value <- 3)
output.OutOfDate |> should be False
output |> AVal.force |> should equal 1

transact (fun () -> a.Value <- 0)
output.OutOfDate |> should be True
output |> AVal.force |> should equal 0

[<Test>]
let ``[AVal] nop change evaluation`` () =

Expand Down

0 comments on commit 3e37064

Please sign in to comment.