<commit_before>﻿namespace SharedCodeFS

open System
open NUnit.Framework
open FsUnit
open Newtonsoft.Json

type Shape =
    | Rectangle of width : float * length : float
    | Circle of radius : float
    | Empty

type SharedFSType() = 
    static member ForCS = "F# into CS"
    static member ForFS = "F# into FS"

[<TestFixture>]
type Test() = 

    [<Test>]
    member x.Test1() =
        Assert.IsTrue(true)

    [<Test>]
    member x.Test2() = 
        1 |> should equal 1

    [<Test>]
    member x.Test3() = 
        "F# into CS" |> should equal SharedFSType.ForCS
        "F# into FS" |> should equal SharedFSType.ForFS

    [<Test>]
    member x.Test4() = 
        let shape1 = Rectangle(1.3, 10.0)
        let shape2 = Circle(2.5)
        let shape3 = Empty
        let json1 = JsonConvert.SerializeObject(shape1)
        let json2 = JsonConvert.SerializeObject(shape2)
        let json3 = JsonConvert.SerializeObject(shape3)
        """
{"Case":"Rectangle","Fields":[1.3,10.0]}
        """.Trim() |> should equal json1
        """
{"Case":"Circle","Fields":[2.5]}
        """.Trim() |> should equal json2
        """
{"Case":"Empty"}
        """.Trim() |> should equal json3
        let parsed1 = JsonConvert.DeserializeObject<Shape> json1
        let parsed2 = JsonConvert.DeserializeObject<Shape> json2
        let parsed3 = JsonConvert.DeserializeObject<Shape> json3
        shape1 |> should equal parsed1
        shape2 |> should equal parsed2
        shape3 |> should equal parsed3
        parsed1 = shape1 |> should be True
        parsed1 = shape2 |> should be False
        parsed1 = shape3 |> should be False
        parsed2 = shape1 |> should be False
        parsed2 = shape2 |> should be True
        parsed2 = shape3 |> should be False
        parsed3 = shape1 |> should be False
        parsed3 = shape2 |> should be False
        parsed3 = shape3 |> should be True<commit_msg>Added JSON parsing exception.<commit_after>﻿namespace SharedCodeFS

open System
open NUnit.Framework
open FsUnit
open Newtonsoft.Json

type Shape =
    | Rectangle of width : float * length : float
    | Circle of radius : float
    | Empty
    | Error

type SharedFSType() = 
    static member ForCS = "F# into CS"
    static member ForFS = "F# into FS"

[<TestFixture>]
type Test() = 

    [<Test>]
    member x.Test1() =
        Assert.IsTrue(true)

    [<Test>]
    member x.Test2() = 
        1 |> should equal 1

    [<Test>]
    member x.Test3() = 
        "F# into CS" |> should equal SharedFSType.ForCS
        "F# into FS" |> should equal SharedFSType.ForFS

    [<Test>]
    member x.Test4() = 
        let shape1 = Rectangle(1.3, 10.0)
        let shape2 = Circle(2.5)
        let shape3 = Empty
        let json1 = JsonConvert.SerializeObject(shape1)
        let json2 = JsonConvert.SerializeObject(shape2)
        let json3 = JsonConvert.SerializeObject(shape3)
        """
{"Case":"Rectangle","Fields":[1.3,10.0]}
        """.Trim() |> should equal json1
        """
{"Case":"Circle","Fields":[2.5]}
        """.Trim() |> should equal json2
        """
{"Case":"Empty"}
        """.Trim() |> should equal json3
        let parsed1 = JsonConvert.DeserializeObject<Shape> json1
        let parsed2 = JsonConvert.DeserializeObject<Shape> json2
        let parsed3 = JsonConvert.DeserializeObject<Shape> json3
        let parse_error =
            try
                JsonConvert.DeserializeObject<Shape> "Meh!"
            with
            | :? JsonException -> Error
        shape1 |> should equal parsed1
        shape2 |> should equal parsed2
        shape3 |> should equal parsed3
        parsed1 = shape1 |> should be True
        parsed1 = shape2 |> should be False
        parsed1 = shape3 |> should be False
        parsed2 = shape1 |> should be False
        parsed2 = shape2 |> should be True
        parsed2 = shape3 |> should be False
        parsed3 = shape1 |> should be False
        parsed3 = shape2 |> should be False
        parsed3 = shape3 |> should be True
        Error = parse_error |> should be True
{'fraction_non_alphanumeric': 0.11270745603170672, 'fraction_numerical': 0.03071587812732227, 'mean_word_length': 2.293637846655791, 'pattern_counts': {'":': 10, '<': 20, '<?xml version=': 0, '>': 58, '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': '2813459', 'n_tokens_mistral': 1277, 'n_tokens_neox': 1236, 'n_words': 360}