<commit_before>﻿module FSharpx.DataStructures.Tests.BKTreeTest

open FSharpx
open FSharpx.DataStructures
open NUnit.Framework
open FsCheck
open FsCheck.NUnit

let fsCheck t = fsCheck "" t

let sem tree = tree |> BKTree.toList |> List.sort

let trans f xs = xs |> BKTree.Int.ofList |> f |> sem

let rec inv m = function
    | Empty -> true
    | Node(a, _, map) ->
        List.forall (fun (d,b) -> BKTree.Int.distance a b = d) m &&
            List.forall (fun (d,t) -> inv ((d,a)::m) t) (IntMap.toList map)

let invariant t = inv [] t

[<Test>]
let ``native empty``() =
    fsCheck <| fun (xs :int list) -><commit_msg>add some BKTree examples to BKTreeTest<commit_after>﻿module FSharpx.DataStructures.Tests.BKTreeTest

open FSharpx
open FSharpx.DataStructures
open NUnit.Framework
open FsUnit

type BS = ByteString

[<Test>]
let ``distance example``() =
    BKTree.ByteString.distance (BS"kitten"B) (BS"sitting"B)
    |> should equal 3

[<Test>]
let ``toListDistance example``() =
    [BS"kitten"B; BS"setting"B; BS"getting"B]
    |> BKTree.ByteString.ofList
    |> BKTree.ByteString.toListDistance 2 (BS"sitting"B)
    |> should equal [BS"setting"B; BS"getting"B]

open FsCheck
open FsCheck.NUnit

let fsCheck t = fsCheck "" t

let sem tree = tree |> BKTree.toList |> List.sort

let trans f xs = xs |> BKTree.Int.ofList |> f |> sem

let rec inv m = function
    | Empty -> true
    | Node(a, _, map) ->
        List.forall (fun (d,b) -> BKTree.Int.distance a b = d) m &&
            List.forall (fun (d,t) -> inv ((d,a)::m) t) (IntMap.toList map)

let invariant t = inv [] t

[<Test>]
let ``native empty``() =
    fsCheck <| fun (xs :int list) ->
{'fraction_non_alphanumeric': 0.15169902912621358, 'fraction_numerical': 0.0012135922330097086, 'mean_word_length': 3.3280839895013123, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 31, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6606940', 'n_tokens_mistral': 648, 'n_tokens_neox': 630, 'n_words': 175}