Skip to content

Improve Gen.list by only testing [] once #377

Description

@TysonMN

I want to improve Gen.list. Actually, what I really want to do is (better) understand Gen.list, and I will be more motivated to do this by having a specific goal to improve it.

Below is code that (if you are lucky) has the following output. It shows that [] is tested many times. Maybe I can figure out how to remove the repeated tests of [].

Requiring luck to investigate this issue slows down progress, so it would be nice if #320 were resolved first.

[0; 1]
├-[]
├-[1]
| ├-[]
| └-[0]
|   └-[]
├-[0]
| └-[]
└-[0; 0]
  ├-[]
  ├-[0]
  | └-[]
  └-[0]
    └-[]

Here is the shrink tree that I desire.

[0; 1]
├-[]
├-[1]
| └-[0]
├-[0]
└-[0; 0]
  ├-[0]
  └-[0]

Even though [0] is also tested twice, my currently feeling is that it is not reasonable to remove that duplication. That comes from either removing the element at index 0 or the element at index 1. Because both elements are 0, both sublists are the same.

let sample =
  Range.constant 0 1
  |> Gen.int32
  |> Gen.list (Range.constant 0 2)
  |> Gen.sampleTree 0 1
  |> Seq.head
  |> Tree.map (sprintf "%A")
  |> Tree.render
printf "%s" sample

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions