<commit_before>module SimpleCipherTest

open System
open NUnit.Framework

open SimpleCipher

let plainText = "abcdefghij"
let key = "<KEY>";

[<Test>]
let ``Encode random uses key made of letters`` () =
    let (key, _) = encodeRandom plainText
    Assert.That(key, Does.Match("[a-z]+"))
    
[<Test>]
[<Ignore("Remove to run test")>]
let ``Encode random uses key of 100 characters`` () =
    let (key, _) = encodeRandom plainText
    Assert.That(key, Has.Length.EqualTo(100))
    
[<Test>]
[<Ignore("Remove to run test")>]
let ``Encode random uses randomly generated key`` () =
    let keys = List.init 100 (fun _ -> encodeRandom plainText |> fst)
    Assert.That(keys |> List.distinct, Is.EqualTo(keys))

// Here we take advantage of the fact that plaintext of "aaa..." doesn't output
// the key. This is a critical problem with shift ciphers, some characters
// will always output the key verbatim.
[<Test>]
[<Ignore("Remove to run test")>]
let ``Encode random can encode`` () =
    let (key, encoded) = encodeRandom "aaaaaaaaaa"
    Assert.That(encoded, Is.EqualTo(key.Substring(0, 10)))

[<Test>]
[<Ignore("Remove to run test")>]
let ``Encode random can decode`` () =    
    let (key, _) = encodeRandom "aaaaaaaaaa"
    Assert.That(decode key (key.Substring(0, 10)), Is.EqualTo("aaaaaaaaaa"))
<commit_msg>Simple cipher: fix comment grammar (#288)<commit_after>module SimpleCipherTest

open System
open NUnit.Framework

open SimpleCipher

let plainText = "abcdefghij"
let key = "<KEY>";

[<Test>]
let ``Encode random uses key made of letters`` () =
    let (key, _) = encodeRandom plainText
    Assert.That(key, Does.Match("[a-z]+"))
    
[<Test>]
[<Ignore("Remove to run test")>]
let ``Encode random uses key of 100 characters`` () =
    let (key, _) = encodeRandom plainText
    Assert.That(key, Has.Length.EqualTo(100))
    
[<Test>]
[<Ignore("Remove to run test")>]
let ``Encode random uses randomly generated key`` () =
    let keys = List.init 100 (fun _ -> encodeRandom plainText |> fst)
    Assert.That(keys |> List.distinct, Is.EqualTo(keys))

// Here we take advantage of the fact that plaintext of "aaa..." outputs
// the key. This is a critical problem with shift ciphers, some characters
// will always output the key verbatim.
[<Test>]
[<Ignore("Remove to run test")>]
let ``Encode random can encode`` () =
    let (key, encoded) = encodeRandom "aaaaaaaaaa"
    Assert.That(encoded, Is.EqualTo(key.Substring(0, 10)))

[<Test>]
[<Ignore("Remove to run test")>]
let ``Encode random can decode`` () =    
    let (key, _) = encodeRandom "aaaaaaaaaa"
    Assert.That(decode key (key.Substring(0, 10)), Is.EqualTo("aaaaaaaaaa"))

{'fraction_non_alphanumeric': 0.1524782444192206, 'fraction_numerical': 0.012485811577752554, 'mean_word_length': 4.133980582524272, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 6, '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': '3095870', 'n_tokens_mistral': 857, 'n_tokens_neox': 831, 'n_words': 282}