<commit_before>﻿(*

Copyright 2013 <NAME>

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

*)

/// Unit tests for the ExtCore.Control.Collections.Async module.
module Tests.ExtCore.Control.Collections.Async

open ExtCore.Control
open ExtCore.Control.Collections
open NUnit.Framework
open FsUnit
//open FsCheck


/// Tests for the ExtCore.Control.Collections.Async.Array module.
module Array =
    [<TestCase>]
    let lift () : unit =
        // Sample usage test cases.
        [| 1; 1; 2; 3; 5; 8; 13; 21; |]
        |> Async.Array.lift
        |> Array.map Async.RunSynchronously
        |> should equal
            [| 1; 1; 2; 3; 5; 8; 13; 21; |]

    [<TestCase>]
    let init () : unit =
        // Test case for creating an empty array.
        Async.Array.init 0 <| fun x ->
            async {
            return x * 17
            }
        |> Async.RunSynchronously
        |> Array.isEmpty
        |> should be True

        // Sample usage test cases.
        Async.Array.init 4 <| fun x ->
            async {
            return x * 17
            }
        |> Async.RunSynchronously
        |> should equal
            [| 0; 17; 34; 51; |]

    [<TestCase>]
    let map () : unit =
        // Sample usage test cases.
        [| 1; 1; 2; 3; 5; 8; 13; 21; |]
        |> Async.Array.map (fun el ->
            async {
            return el * 3
            })
        |> Async.RunSynchronously
        |> should equal
            [| 3; 3; 6; 9; 15; 24; 39; 63; |]

    [<TestCase>]
    let mapi () : unit =
        // Sample usage test cases.
        [| 1; 1; 2; 3; 5; 8; 13; 21; |]
        |> Async.Array.mapi (fun idx el ->
            async {
            return idx + el
            })
        |> Async.RunSynchronously
        |> should equal
            [1; 2; 4; 6; 9; 13; 19; 28]

    [<TestCase>]
    let map2 () : unit =
        Assert.Inconclusive "Test not yet implemented."

    [<TestCase>]
    let mapi2 () : unit =
        Assert.Inconclusive "Test not yet implemented."

    [<TestCase>]
    let mapPartition () : unit =
        Assert.Inconclusive "Test not yet implemented."

    [<TestCase>]
    let fold () : unit =
        // Sample usage test cases.
        (String.empty, [| 2; 17; 4; 12; |])
        ||> Async.Array.fold (fun state x ->
            async {
            return state + x.ToString()
            })
        |> Async.RunSynchronously
        |> should equal "217412"

    [<TestCase>]
    let foldBack () : unit =
        Assert.Inconclusive "Test not yet implemented."

    [<TestCase>]
    let foldi () : unit =
        // Sample usage test cases.
        (String.empty, [| 2; 17; 4; 12; |])
        ||> Async.Array.foldi (fun state idx x ->
            async {
            return state + (x + idx).ToString()
            })
        |> Async.RunSynchronously
        |> should equal "218615"

    [<TestCase>]
    let foldiBack () : unit =
        Assert.Inconclusive "Test not yet implemented."

    [<TestCase>]
    let iter () : unit =
        do
            // Test case for an empty array.
            let elements = ResizeArray ()

            Array.empty
            |> Async.Array.iter (fun x ->
                async {
                do elements.Add (x * 3)
                })
            |> Async.RunSynchronously

            ResizeArray.isEmpty elements
            |> should be True

        do
            // Sample usage test case.<commit_msg>Implemented some unit tests for Async.Array functions.<commit_after>﻿(*

Copyright 2013 <NAME>

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

*)

/// Unit tests for the ExtCore.Control.Collections.Async module.
module Tests.ExtCore.Control.Collections.Async

open ExtCore.Control
open ExtCore.Control.Collections
open NUnit.Framework
open FsUnit
//open FsCheck


/// Tests for the ExtCore.Control.Collections.Async.Array module.
module Array =
    [<TestCase>]
    let lift () : unit =
        // Sample usage test cases.
        [| 1; 1; 2; 3; 5; 8; 13; 21; |]
        |> Async.Array.lift
        |> Array.map Async.RunSynchronously
        |> should equal
            [| 1; 1; 2; 3; 5; 8; 13; 21; |]

    [<TestCase>]
    let init () : unit =
        // Test case for creating an empty array.
        Async.Array.init 0 <| fun x ->
            async {
            return x * 17
            }
        |> Async.RunSynchronously
        |> Array.isEmpty
        |> should be True

        // Sample usage test cases.
        Async.Array.init 4 <| fun x ->
            async {
            return x * 17
            }
        |> Async.RunSynchronously
        |> should equal
            [| 0; 17; 34; 51; |]

    [<TestCase>]
    let map () : unit =
        // Sample usage test cases.
        [| 1; 1; 2; 3; 5; 8; 13; 21; |]
        |> Async.Array.map (fun el ->
            async {
            return el * 3
            })
        |> Async.RunSynchronously
        |> should equal
            [| 3; 3; 6; 9; 15; 24; 39; 63; |]

    [<TestCase>]
    let mapi () : unit =
        // Sample usage test cases.
        [| 1; 1; 2; 3; 5; 8; 13; 21; |]
        |> Async.Array.mapi (fun idx el ->
            async {
            return idx + el
            })
        |> Async.RunSynchronously
        |> should equal
            [1; 2; 4; 6; 9; 13; 19; 28]

    [<TestCase>]
    let map2 () : unit =
        Assert.Inconclusive "Test not yet implemented."

    [<TestCase>]
    let mapi2 () : unit =
        Assert.Inconclusive "Test not yet implemented."

    [<TestCase>]
    let mapPartition () : unit =
        Assert.Inconclusive "Test not yet implemented."

    [<TestCase>]
    let fold () : unit =
        // Sample usage test cases.
        (String.empty, [| 2; 17; 4; 12; |])
        ||> Async.Array.fold (fun state x ->
            async {
            return state + x.ToString()
            })
        |> Async.RunSynchronously
        |> should equal "217412"

    [<TestCase>]
    let foldBack () : unit =
        // Sample usage test cases.
        ([| 2; 17; 4; 12; |], String.empty)
        ||> Async.Array.foldBack (fun x state ->
            async {
            return state + x.ToString()
            })
        |> Async.RunSynchronously
        |> should equal "124172"

    [<TestCase>]
    let foldi () : unit =
        // Sample usage test cases.
        (String.empty, [| 2; 17; 4; 12; |])
        ||> Async.Array.foldi (fun state idx x ->
            async {
            return state + (x + idx).ToString()
            })
        |> Async.RunSynchronously
        |> should equal "218615"

    [<TestCase>]
    let foldiBack () : unit =
        // Sample usage test cases.
        ([| 2; 17; 4; 12; |], String.empty)
        ||> Async.Array.foldiBack (fun idx x state ->
            async {
            return state + (x + idx).ToString()
            })
        |> Async.RunSynchronously
        |> should equal "156182"

    [<TestCase>]
    let iter () : unit =
        do
            // Test case for an empty array.
            let elements = ResizeArray ()

            Array.empty
            |> Async.Array.iter (fun x ->
                async {
                do elements.Add (x * 3)
                })
            |> Async.RunSynchronously

            ResizeArray.isEmpty elements
            |> should be True

        do
            // Sample usage test case.
{'fraction_non_alphanumeric': 0.11712693798449612, 'fraction_numerical': 0.030038759689922482, 'mean_word_length': 1.6129746835443037, 'pattern_counts': {'":': 0, '<': 33, '<?xml version=': 0, '>': 97, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '1355849', 'n_tokens_mistral': 2664, 'n_tokens_neox': 2321, 'n_words': 797}