Skip to content

Commit

Permalink
Add changes before using paket and fake
Browse files Browse the repository at this point in the history
  • Loading branch information
Release-Candidate committed Apr 25, 2021
1 parent b908b67 commit c2e2990
Show file tree
Hide file tree
Showing 12 changed files with 169 additions and 83 deletions.
6 changes: 6 additions & 0 deletions .config/dotnet-tools.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@
"commands": [
"fabulous"
]
},
"altcover.visualizer": {
"version": "8.1.819",
"commands": [
"altcover.visualizer"
]
}
}
}
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
Pipfile.lock

# Coverage data
coverage.xml
*.xml*.acv
*coverage.*
*.exn

# Fake and Ionide directories
Expand All @@ -33,3 +34,5 @@ paket-files/
.ipynb_checkpoints/
/src/TzolkinDate/Properties/PublishProfiles
/src/TzolkinDate/TzolkinDate.fsproj.user


5 changes: 5 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"dotnet-test-explorer.autoWatch": true,
"dotnet-test-explorer.runInParallel": true,
"dotnet-test-explorer.testProjectPath": "tests/*/*.fsproj"
}
8 changes: 4 additions & 4 deletions Tzolkin.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"text/html": [
"\r\n",
"<div>\r\n",
" <div id='dotnet-interactive-this-cell-10588.Microsoft.DotNet.Interactive.Http.HttpPort' style='display: none'>\r\n",
" <div id='dotnet-interactive-this-cell-26508.Microsoft.DotNet.Interactive.Http.HttpPort' style='display: none'>\r\n",
" The below script needs to be able to find the current output cell; this is an easy method to get it.\r\n",
" </div>\r\n",
" <script type='text/javascript'>\r\n",
Expand Down Expand Up @@ -89,7 +89,7 @@
" // use probing to find host url and api resources\r\n",
" // load interactive helpers and language services\r\n",
" let dotnetInteractiveRequire = require.config({\r\n",
" context: '10588.Microsoft.DotNet.Interactive.Http.HttpPort',\r\n",
" context: '26508.Microsoft.DotNet.Interactive.Http.HttpPort',\r\n",
" paths:\r\n",
" {\r\n",
" 'dotnet-interactive': `${root}resources`\r\n",
Expand Down Expand Up @@ -202,7 +202,7 @@
{
"data": {
"text/html": [
"<table><thead><tr><th>Number</th><th>Glyph</th></tr></thead><tbody><tr><td><div class=\"dni-plaintext\">8</div></td><td><div class=\"dni-plaintext\">Kimi</div></td></tr></tbody></table>"
"<table><thead><tr><th>Number</th><th>Glyph</th></tr></thead><tbody><tr><td><div class=\"dni-plaintext\">9</div></td><td><div class=\"dni-plaintext\">Manikʼ</div></td></tr></tbody></table>"
]
},
"execution_count": 3,
Expand Down Expand Up @@ -1194,7 +1194,7 @@
{
"data": {
"text/html": [
"<table><thead><tr><th>Number</th><th>Glyph</th></tr></thead><tbody><tr><td><div class=\"dni-plaintext\">8</div></td><td><div class=\"dni-plaintext\">Kimi</div></td></tr></tbody></table>"
"<table><thead><tr><th>Number</th><th>Glyph</th></tr></thead><tbody><tr><td><div class=\"dni-plaintext\">9</div></td><td><div class=\"dni-plaintext\">Manikʼ</div></td></tr></tbody></table>"
]
},
"execution_count": 39,
Expand Down
3 changes: 3 additions & 0 deletions Tzolkin.sln
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,11 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
publish_nuget.bat = publish_nuget.bat
publish_nuget.sh = publish_nuget.sh
README.md = README.md
run_coverage.bat = run_coverage.bat
run_sharplint.bat = run_sharplint.bat
run_sharplint.sh = run_sharplint.sh
run_tests.bat = run_tests.bat
.vscode\settings.json = .vscode\settings.json
Tzolkin.ipynb = Tzolkin.ipynb
EndProjectSection
EndProject
Expand Down
5 changes: 3 additions & 2 deletions src/TzolkinDate/TzolkinDate.fs
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,15 @@ module TzolkinDate =
/// Calculate Tzolk’in day in a year 'modulo'.
/// Calculate `n` % 260 and return 260 if `n` = 0 (mod 260), because a day 0 doesn't
/// make sense and by returning 260 we still have a mathematical ring.
/// For negative integers `n` `260 - (n % 260)` is returned.
///
/// Params:
/// `n` The integer to calculate the 'Tzolk’in day modulo' of.
///
/// Returns:
/// 260 if `n` = 0 (mod20)
/// 260 if `n` = 0 (mod 260)
/// `n` % 260 else.
let modulo260 n = if n % 260 = 0 then 260 else n % 260
let modulo260 = Generics.modulo 260

/// The `TzolkinDate` type, holding the Tzolk’in day number in `number` and day
/// glyph in `glyph`.
Expand Down
1 change: 1 addition & 0 deletions src/TzolkinDate/TzolkinDate.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<OtherFlags>--warnon:3390</OtherFlags>
<WarningLevel>5</WarningLevel>
<OutputPath>$(SolutionDir)\bin\</OutputPath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
<OtherFlags>--warnon:3390</OtherFlags>
Expand Down
56 changes: 32 additions & 24 deletions tests/TestTzolkin/Generic.fs
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,29 @@ open Expecto.Logging
[<AutoOpen>]
module Generic=

let logger = Log.create "Tzolkin"
let private logger = Log.create "Tzolkin"

let private loggerFunc logFunc moduleName name no args =
logFunc (
Message.eventX "{module} '{test}' #{no}, generated '{args}'"
>> Message.setField "module" moduleName
>> Message.setField "test" name
>> Message.setField "no" no
>> Message.setField "args" args )

let loggerFuncDeb moduleName name no args =
loggerFunc logger.debugWithBP moduleName name no args

let loggerFuncInfo moduleName name no args =
loggerFunc logger.infoWithBP moduleName name no args

let config = { FsCheckConfig.defaultConfig with
maxTest = 100000
endSize = 1000000
receivedArgs = fun _ name no args ->
logger.infoWithBP (
Message.eventX "For {test} {no}, generated {args}"
>> Message.setField "test" name
>> Message.setField "no" no
>> Message.setField "args" args)}

let configList = { config with
maxTest = 100000
endSize = 1000000 }

let configList = { FsCheckConfig.defaultConfig with
maxTest = 25
endSize = 10000 }
endSize = 500 }

// Rules to calculate with `TzolkinNumber` and `TzolkinGlyph`. =================================

Expand Down Expand Up @@ -145,33 +153,33 @@ module Generic=
|> List.iter (fun elem -> testNextDateHelper1 nextDate cycleLength elem isLast)


let inline testNextList nextDateList numDates cycleLength referenceDates isLast =
let rec testList list difference =
let inline testNextList nextDateList fromDate numDates cycleLength referenceDates isLast =
let rec testList list fromDate tzolkin difference =
match list with
| head :: (head2 :: tail) ->
test <@ head2 - head = TimeSpan.FromDays difference @>
testList (head2 :: tail) difference
| [_] -> ()
test <@ fromDate head = tzolkin @>
testList (head2 :: tail) fromDate tzolkin difference
| [head] -> test <@ fromDate head = tzolkin @>
| [] -> ()

let testNextListHelper2 numDates nextDateList cycleLength referenceDate days isLast =
let testNextListHelper2 fromDate numDates nextDateList cycleLength referenceDate days isLast =
let (date:DateTime), tzolkin = referenceDate
let start = date + TimeSpan.FromDays (float days)
let listToTest: DateTime list = nextDateList numDates tzolkin start
if isLast then
test <@ listToTest.Head = date @>
testList listToTest (float -cycleLength)
testList listToTest fromDate tzolkin (float -cycleLength)
else
test <@ listToTest.Head = date + TimeSpan.FromDays (float cycleLength) @>
testList listToTest (float cycleLength)

testList listToTest fromDate tzolkin (float cycleLength)

let testNextListHelper1 numDates nextDateList cycleLength referenceDate isLast =
Gen.choose (0, cycleLength - 1) |> Gen.sample 0 10
|> List.iter (fun i -> testNextListHelper2 numDates nextDateList cycleLength referenceDate i isLast)
let testNextListHelper1 numDates fromDate nextDateList cycleLength referenceDate isLast =
Gen.choose (0, cycleLength - 1) |> Gen.sample 0 5
|> List.iter (fun i -> testNextListHelper2 fromDate numDates nextDateList cycleLength referenceDate i isLast)

referenceDates
|> List.iter (fun elem -> testNextListHelper1 numDates nextDateList cycleLength elem isLast)
|> List.iter (fun elem -> testNextListHelper1 numDates fromDate nextDateList cycleLength elem isLast)



81 changes: 41 additions & 40 deletions tests/TestTzolkin/TestTzolkin.fsproj
Original file line number Diff line number Diff line change
@@ -1,42 +1,43 @@
<?xml version="1.0" encoding="utf-8"?>
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net5.0</TargetFramework>
<GenerateProgramFile>false</GenerateProgramFile>
<Configurations>Debug;Release;Release APK</Configurations>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<WarningLevel>5</WarningLevel>
<OtherFlags>--warnon:3390</OtherFlags>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
<OtherFlags>--warnon:3390</OtherFlags>
<WarningLevel>5</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release APK|AnyCPU'">
<OtherFlags>--warnon:3390</OtherFlags>
<WarningLevel>5</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Compile Include="Generic.fs" />
<Compile Include="TestTzolkinNumber.fs" />
<Compile Include="TestTzolkinGlyph.fs" />
<Compile Include="TestTzolkinDate.fs" />
<Compile Include="TestMain.fs" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="AltCover" Version="8.1.819" />
<PackageReference Include="Expecto" Version="9.*" />
<PackageReference Include="Expecto.FsCheck" Version="9.0.2" />
<PackageReference Include="Unquote" Version="5.0.0" />
<PackageReference Include="YoloDev.Expecto.TestSdk" Version="0.*" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.*" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\src\TzolkinDate\TzolkinDate.fsproj" />
</ItemGroup>
<ItemGroup>
<PackageReference Update="FSharp.Core" Version="5.0.1" />
</ItemGroup>
</Project>
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net5.0</TargetFramework>
<GenerateProgramFile>false</GenerateProgramFile>
<Configurations>Debug;Release;Release APK</Configurations>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<WarningLevel>5</WarningLevel>
<OtherFlags>--warnon:3390</OtherFlags>
<OutputPath>$(SolutionDir)\bin\</OutputPath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
<OtherFlags>--warnon:3390</OtherFlags>
<WarningLevel>5</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release APK|AnyCPU'">
<OtherFlags>--warnon:3390</OtherFlags>
<WarningLevel>5</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Compile Include="Generic.fs" />
<Compile Include="TestTzolkinNumber.fs" />
<Compile Include="TestTzolkinGlyph.fs" />
<Compile Include="TestTzolkinDate.fs" />
<Compile Include="TestMain.fs" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="AltCover" Version="8.1.819" />
<PackageReference Include="Expecto" Version="9.*" />
<PackageReference Include="Expecto.FsCheck" Version="9.0.2" />
<PackageReference Include="Unquote" Version="5.0.0" />
<PackageReference Include="YoloDev.Expecto.TestSdk" Version="0.*" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.*" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\src\TzolkinDate\TzolkinDate.fsproj" />
</ItemGroup>
<ItemGroup>
<PackageReference Update="FSharp.Core" Version="5.0.1" />
</ItemGroup>
</Project>
29 changes: 24 additions & 5 deletions tests/TestTzolkin/TestTzolkinDate.fs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
namespace TestTzolkin

open Expecto
open Swensen.Unquote
open System

open RC.Maya
Expand All @@ -18,11 +17,19 @@ open RC.Maya
[<AutoOpen>]
module TestTzolkinDate=

let config = { config with
receivedArgs = fun _ name no args ->
loggerFuncDeb "TestTzolkinDate" name no args }

let configList = { configList with
receivedArgs = fun _ name no args ->
loggerFuncInfo "TestTzolkinDate" name no args }

let inline stringList2DateListDate list =
List.map (fun (date, number, glyph) ->
stringToDate date,
{TzolkinDate.Number = TzolkinNumber.T.TzolkinNumber number
TzolkinDate.Glyph = TzolkinGlyph.T.TzolkinGlyph glyph}
{ TzolkinDate.Number = TzolkinNumber.T.TzolkinNumber number
TzolkinDate.Glyph = TzolkinGlyph.T.TzolkinGlyph glyph }
)
list

Expand Down Expand Up @@ -101,10 +108,22 @@ module TestTzolkinDate=

testPropertyWithConfig configList "getNextList with a reference date list"
<| fun i ->
testNextList TzolkinDate.getNextList (abs i) 260 referenceDates false
testNextList
TzolkinDate.getNextList
TzolkinDate.fromDate
(abs i)
260
referenceDates
false

testPropertyWithConfig configList "getLastList with a reference date list"
<| fun i ->
testNextList TzolkinDate.getLastList (abs i) 260 referenceDates true
testNextList
TzolkinDate.getLastList
TzolkinDate.fromDate
(abs i)
260
referenceDates
true

]
28 changes: 24 additions & 4 deletions tests/TestTzolkin/TestTzolkinGlyph.fs
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,22 @@
namespace TestTzolkin

open Expecto
open Swensen.Unquote
open System

open RC.Maya
open System


[<AutoOpen>]
module TestTzolkinGlyph=

let config = { config with
receivedArgs = fun _ name no args ->
loggerFuncDeb "TestTzolkinGlyph" name no args }

let configList = { configList with
receivedArgs = fun _ name no args ->
loggerFuncInfo "TestTzolkinGlyph" name no args }

let referenceDates = [ ("01.01.1800", 14)
("12.12.1926", 19)
("26.01.1958", 7)
Expand Down Expand Up @@ -90,10 +98,22 @@ module TestTzolkinGlyph=

testPropertyWithConfig configList "getNextList with a reference date list"
<| fun i ->
testNextList TzolkinGlyph.getNextList (abs i) 20 referenceDates false
testNextList
TzolkinGlyph.getNextList
TzolkinGlyph.fromDate
(abs i)
20
referenceDates
false

testPropertyWithConfig configList "getLastList with a reference date list"
<| fun i ->
testNextList TzolkinGlyph.getLastList (abs i) 20 referenceDates true
testNextList
TzolkinGlyph.getLastList
TzolkinGlyph.fromDate
(abs i)
20
referenceDates
true

]

0 comments on commit c2e2990

Please sign in to comment.