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

Add a F# version of Stalin Sort #63

Open
wants to merge 1 commit into
base: master
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
48 changes: 48 additions & 0 deletions Fsharp/stalin-sort/stalin-sort.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.26124.0
MinimumVisualStudioVersion = 15.0.26124.0
Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "stalin-sort", "stalin-sort\stalin-sort.fsproj", "{0EEBA97A-F776-4E14-AC59-5DFFE1EACFC6}"
EndProject
Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "stalin-sort.tests", "stalin-sort.tests\stalin-sort.tests.fsproj", "{FAA4CA87-6529-430C-835D-54B42018EB59}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Debug|x64 = Debug|x64
Debug|x86 = Debug|x86
Release|Any CPU = Release|Any CPU
Release|x64 = Release|x64
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{0EEBA97A-F776-4E14-AC59-5DFFE1EACFC6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{0EEBA97A-F776-4E14-AC59-5DFFE1EACFC6}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0EEBA97A-F776-4E14-AC59-5DFFE1EACFC6}.Debug|x64.ActiveCfg = Debug|Any CPU
{0EEBA97A-F776-4E14-AC59-5DFFE1EACFC6}.Debug|x64.Build.0 = Debug|Any CPU
{0EEBA97A-F776-4E14-AC59-5DFFE1EACFC6}.Debug|x86.ActiveCfg = Debug|Any CPU
{0EEBA97A-F776-4E14-AC59-5DFFE1EACFC6}.Debug|x86.Build.0 = Debug|Any CPU
{0EEBA97A-F776-4E14-AC59-5DFFE1EACFC6}.Release|Any CPU.ActiveCfg = Release|Any CPU
{0EEBA97A-F776-4E14-AC59-5DFFE1EACFC6}.Release|Any CPU.Build.0 = Release|Any CPU
{0EEBA97A-F776-4E14-AC59-5DFFE1EACFC6}.Release|x64.ActiveCfg = Release|Any CPU
{0EEBA97A-F776-4E14-AC59-5DFFE1EACFC6}.Release|x64.Build.0 = Release|Any CPU
{0EEBA97A-F776-4E14-AC59-5DFFE1EACFC6}.Release|x86.ActiveCfg = Release|Any CPU
{0EEBA97A-F776-4E14-AC59-5DFFE1EACFC6}.Release|x86.Build.0 = Release|Any CPU
{FAA4CA87-6529-430C-835D-54B42018EB59}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{FAA4CA87-6529-430C-835D-54B42018EB59}.Debug|Any CPU.Build.0 = Debug|Any CPU
{FAA4CA87-6529-430C-835D-54B42018EB59}.Debug|x64.ActiveCfg = Debug|Any CPU
{FAA4CA87-6529-430C-835D-54B42018EB59}.Debug|x64.Build.0 = Debug|Any CPU
{FAA4CA87-6529-430C-835D-54B42018EB59}.Debug|x86.ActiveCfg = Debug|Any CPU
{FAA4CA87-6529-430C-835D-54B42018EB59}.Debug|x86.Build.0 = Debug|Any CPU
{FAA4CA87-6529-430C-835D-54B42018EB59}.Release|Any CPU.ActiveCfg = Release|Any CPU
{FAA4CA87-6529-430C-835D-54B42018EB59}.Release|Any CPU.Build.0 = Release|Any CPU
{FAA4CA87-6529-430C-835D-54B42018EB59}.Release|x64.ActiveCfg = Release|Any CPU
{FAA4CA87-6529-430C-835D-54B42018EB59}.Release|x64.Build.0 = Release|Any CPU
{FAA4CA87-6529-430C-835D-54B42018EB59}.Release|x86.ActiveCfg = Release|Any CPU
{FAA4CA87-6529-430C-835D-54B42018EB59}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
EndGlobal
2 changes: 2 additions & 0 deletions Fsharp/stalin-sort/stalin-sort.tests/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
bin/
obj/
1 change: 1 addition & 0 deletions Fsharp/stalin-sort/stalin-sort.tests/Program.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module Program = let [<EntryPoint>] main _ = 0
26 changes: 26 additions & 0 deletions Fsharp/stalin-sort/stalin-sort.tests/UnitTest1.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
namespace Tests

open System
open NUnit.Framework
open Program

[<TestClass>]
type TestClass () =

[<SetUp>]
member this.Setup () =
()

[<Test>]
member this.Test1 () =
let nonsorted_list = [1; 2; 4; 3; 6; 8; 0; 9; 5; 7]
let sorted_list_ref = [1; 2; 4; 6; 8; 9]
let sorted_list_exp = Program.StalinSort nonsorted_list
Assert.True((List.length sorted_list_ref) = (List.length sorted_list_exp))

[<Test>]
member this.Test2 () =
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is the result of a list with repeated numbers like 1 2 4 4 3 6?

let nonsorted_list = [1; 2; 1; 1; 4; 3; 9]
let sorted_list_ref = [1; 2; 4; 9]
let sorted_list_exp = Program.StalinSort nonsorted_list
Assert.True((List.length sorted_list_ref) = (List.length sorted_list_exp))
24 changes: 24 additions & 0 deletions Fsharp/stalin-sort/stalin-sort.tests/stalin-sort.tests.fsproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp2.1</TargetFramework>

<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="nunit" Version="3.10.1" />
<PackageReference Include="NUnit3TestAdapter" Version="3.10.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.8.0" />
</ItemGroup>

<ItemGroup>
<Compile Include="UnitTest1.fs" />
<Compile Include="Program.fs" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\stalin-sort\stalin-sort.fsproj" />
</ItemGroup>

</Project>
2 changes: 2 additions & 0 deletions Fsharp/stalin-sort/stalin-sort/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
bin/
obj/
25 changes: 25 additions & 0 deletions Fsharp/stalin-sort/stalin-sort/Program.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Learn more about F# at http://fsharp.org

open System

let rec StalinSort x =
match x with
| [] -> []
| [x] -> [x]
| x :: xs ->
match xs with
| [] -> [x]
| [y] -> if x <= y then [x; y] else [x]
| y :: ys -> if x <= y then [x] @ (StalinSort ([y] @ ys)) else (StalinSort ([x] @ ys))

[<EntryPoint>]
let main argv =
let nonsorted_list_1 = [1; 2; 4; 3; 6; 8; 0; 9; 5; 7]
let sorted_list_1 = StalinSort nonsorted_list_1

let nonsorted_list_2 = [1; 2; 1; 1; 4; 3; 9]
let sorted_list_2 = StalinSort nonsorted_list_2

Console.WriteLine("{0}", System.String.Join(", ", sorted_list_1))
Console.WriteLine("{0}", System.String.Join(", ", sorted_list_2))
0
13 changes: 13 additions & 0 deletions Fsharp/stalin-sort/stalin-sort/stalin-sort.fsproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.1</TargetFramework>
<RootNamespace>stalin_sort</RootNamespace>
</PropertyGroup>

<ItemGroup>
<Compile Include="Program.fs" />
</ItemGroup>

</Project>