Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Factorial #1

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions src/Homework1/Factorial.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
namespace Homework1

/// <summary>
/// Module that implements method that calculates factorial.
/// </summary>
module Factorial =
/// <summary>
/// Calculates factorial.
/// </summary>
/// <param name="number">Last number in factorial.</param>
let factorial number =
let rec factorialRec acc n =
match n with
| 0
| 1 -> acc
| _ -> factorialRec (acc * n) (n - 1)

match number with
| _ when number < 0 -> None
| _ -> Some(factorialRec 1 number)
1 change: 1 addition & 0 deletions src/Homework1/Homework1.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
</PropertyGroup>
<ItemGroup>
<Content Include="paket.references" />
<Compile Include="Factorial.fs" />
<Compile Include="Main.fs" />
</ItemGroup>
<Import Project="..\..\.paket\Paket.Restore.targets" />
Expand Down
3 changes: 1 addition & 2 deletions tests/Homeworks.Tests/Main.fs
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,4 @@ let allTests = testList "all Tests" []

[<EntryPoint>]
let main argv =
allTests
|> runTestsWithCLIArgs [] argv
allTests |> runTestsWithCLIArgs [] argv