diff --git a/.gitignore b/.gitignore index 74941b9..d0f9f16 100644 --- a/.gitignore +++ b/.gitignore @@ -1,336 +1,40 @@ -## Ignore Visual Studio temporary files, build results, and -## files generated by popular Visual Studio add-ons. -## -## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore - -# User-specific files -*.suo -*.user -*.userosscache -*.sln.docstates - -# User-specific files (MonoDevelop/Xamarin Studio) -*.userprefs - -# Build results -[Dd]ebug/ -[Dd]ebugPublic/ -[Rr]elease/ -[Rr]eleases/ -x64/ -x86/ -bld/ -[Bb]in/ -[Oo]bj/ -[Ll]og/ - -# Visual Studio 2015/2017 cache/options directory -.vs/ -# Uncomment if you have tasks that create the project's static files in wwwroot -#wwwroot/ - -# Visual Studio 2017 auto generated files -Generated\ Files/ - -# MSTest test Results -[Tt]est[Rr]esult*/ -[Bb]uild[Ll]og.* - -# NUNIT -*.VisualState.xml -TestResult.xml - -# Build Results of an ATL Project -[Dd]ebugPS/ -[Rr]eleasePS/ -dlldata.c - -# Benchmark Results -BenchmarkDotNet.Artifacts/ - -# .NET Core -project.lock.json -project.fragment.lock.json -artifacts/ -**/Properties/launchSettings.json - -# StyleCop -StyleCopReport.xml - -# Files built by Visual Studio -*_i.c -*_p.c -*_i.h -*.ilk -*.meta -*.obj -*.iobj -*.pch -*.pdb -*.ipdb -*.pgc -*.pgd -*.rsp -*.sbr -*.tlb -*.tli -*.tlh -*.tmp -*.tmp_proj -*.log -*.vspscc -*.vssscc -.builds -*.pidb -*.svclog -*.scc - -# Chutzpah Test files -_Chutzpah* - -# Visual C++ cache files -ipch/ -*.aps -*.ncb -*.opendb -*.opensdf -*.sdf -*.cachefile -*.VC.db -*.VC.VC.opendb - -# Visual Studio profiler -*.psess -*.vsp -*.vspx -*.sap - -# Visual Studio Trace Files -*.e2e - -# TFS 2012 Local Workspace -$tf/ - -# Guidance Automation Toolkit -*.gpState - -# ReSharper is a .NET coding add-in -_ReSharper*/ -*.[Rr]e[Ss]harper -*.DotSettings.user - -# JustCode is a .NET coding add-in -.JustCode - -# TeamCity is a build add-in -_TeamCity* - -# DotCover is a Code Coverage Tool -*.dotCover - -# AxoCover is a Code Coverage Tool -.axoCover/* -!.axoCover/settings.json - -# Visual Studio code coverage results -*.coverage -*.coveragexml - -# NCrunch -_NCrunch_* -.*crunch*.local.xml -nCrunchTemp_* - -# MightyMoose -*.mm.* -AutoTest.Net/ - -# Web workbench (sass) -.sass-cache/ - -# Installshield output folder -[Ee]xpress/ - -# DocProject is a documentation generator add-in -DocProject/buildhelp/ -DocProject/Help/*.HxT -DocProject/Help/*.HxC -DocProject/Help/*.hhc -DocProject/Help/*.hhk -DocProject/Help/*.hhp -DocProject/Help/Html2 -DocProject/Help/html - -# Click-Once directory -publish/ - -# Publish Web Output -*.[Pp]ublish.xml -*.azurePubxml -# Note: Comment the next line if you want to checkin your web deploy settings, -# but database connection strings (with potential passwords) will be unencrypted -*.pubxml -*.publishproj - -# Microsoft Azure Web App publish settings. Comment the next line if you want to -# checkin your Azure Web App publish settings, but sensitive information contained -# in these scripts will be unencrypted -PublishScripts/ - -# NuGet Packages -*.nupkg -# The packages folder can be ignored because of Package Restore -**/[Pp]ackages/* -# except build/, which is used as an MSBuild target. -!**/[Pp]ackages/build/ -# Uncomment if necessary however generally it will be regenerated when needed -#!**/[Pp]ackages/repositories.config -# NuGet v3's project.json files produces more ignorable files -*.nuget.props -*.nuget.targets - -# Microsoft Azure Build Output -csx/ -*.build.csdef - -# Microsoft Azure Emulator -ecf/ -rcf/ - -# Windows Store app package directories and files -AppPackages/ -BundleArtifacts/ -Package.StoreAssociation.xml -_pkginfo.txt -*.appx - -# Visual Studio cache files -# files ending in .cache can be ignored -*.[Cc]ache -# but keep track of directories ending in .cache -!*.[Cc]ache/ - -# Others -ClientBin/ -~$* -*~ -*.dbmdl -*.dbproj.schemaview -*.jfm -*.pfx -*.publishsettings -orleans.codegen.cs - -# Including strong name files can present a security risk -# (https://github.com/github/gitignore/pull/2483#issue-259490424) -#*.snk - -# Since there are multiple workflows, uncomment next line to ignore bower_components -# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) -#bower_components/ - -# RIA/Silverlight projects -Generated_Code/ - -# Backup & report files from converting an old project file -# to a newer Visual Studio version. Backup files are not needed, -# because we have git ;-) -_UpgradeReport_Files/ -Backup*/ -UpgradeLog*.XML -UpgradeLog*.htm -ServiceFabricBackup/ -*.rptproj.bak - -# SQL Server files -*.mdf -*.ldf -*.ndf - -# Business Intelligence projects -*.rdl.data -*.bim.layout -*.bim_*.settings -*.rptproj.rsuser - -# Microsoft Fakes -FakesAssemblies/ - -# GhostDoc plugin setting file -*.GhostDoc.xml - -# Node.js Tools for Visual Studio -.ntvs_analysis.dat -node_modules/ - -# Visual Studio 6 build log -*.plg - -# Visual Studio 6 workspace options file -*.opt - -# Visual Studio 6 auto-generated workspace file (contains which files were open etc.) -*.vbw - -# Visual Studio LightSwitch build output -**/*.HTMLClient/GeneratedArtifacts -**/*.DesktopClient/GeneratedArtifacts -**/*.DesktopClient/ModelManifest.xml -**/*.Server/GeneratedArtifacts -**/*.Server/ModelManifest.xml -_Pvt_Extensions - -# Paket dependency manager -.paket/paket.exe -paket-files/ - -# FAKE - F# Make -.fake/ - -# JetBrains Rider -.idea/ -*.sln.iml - -# CodeRush -.cr/ - -# Python Tools for Visual Studio (PTVS) -__pycache__/ -*.pyc - -# Cake - Uncomment if you are using it -# tools/** -# !tools/packages.config - -# Tabs Studio -*.tss - -# Telerik's JustMock configuration file -*.jmconfig - -# BizTalk build output -*.btp.cs -*.btm.cs -*.odx.cs -*.xsd.cs - -# OpenCover UI analysis results -OpenCover/ - -# Azure Stream Analytics local run output -ASALocalRun/ - -# MSBuild Binary and Structured Log -*.binlog - -# NVidia Nsight GPU debugger configuration file -*.nvuser - -# MFractors (Xamarin productivity tool) working folder -.mfractor/ -.user -.filters -#This is mine and this is now -.bin/ -.obj/ -.Properties/ \ No newline at end of file +# Prerequisites +*.d + +# Compiled Object files +*.slo +*.lo +*.o +*.obj + +# Precompiled Headers +*.gch +*.pch + +# Compiled Dynamic libraries +*.so +*.dylib +*.dll + +# Fortran module files +*.mod +*.smod + +# Compiled Static libraries +*.lai +*.la +*.a +*.lib + +# Executables +*.exe +*.out +*.app + +# Another things (VS) +**/.vs +*.vcxproj.user +**/Debug +**/bin +**/obj +*/packages \ No newline at end of file diff --git a/appveyor.yml b/appveyor.yml index 855f34f..4c4b1c1 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -1,7 +1,7 @@ -image: Visual Studio 2017 +image: Visual Studio 2019 before_build: - - nuget restore semester2/6.1/HW6T2.sln + - nuget restore semester4/HomeworkOne/HomeworkOne.sln build: - project: semester2/2.3/2.3.sln + project: semester4/HomeworkOne/HomeworkOne.sln diff --git a/semester4/HomeworkOne/HomeworkOne.Tests/Factorial.Tests.fs b/semester4/HomeworkOne/HomeworkOne.Tests/Factorial.Tests.fs new file mode 100644 index 0000000..479d81c --- /dev/null +++ b/semester4/HomeworkOne/HomeworkOne.Tests/Factorial.Tests.fs @@ -0,0 +1,20 @@ +module Factorial.Tests + +open System +open FsUnit +open NUnit.Framework +open Factorial + +[] +let ``factorial of negative numbers``() = + (fun() -> factorial -1 |> ignore) |> should throw typeof + (fun() -> factorial -10 |> ignore) |> should throw typeof + (fun() -> factorial -1242141 |> ignore) |> should throw typeof + +[] +let ``factorial of positive numbers and zero`` () = + factorial 3 |> should equal 6 + factorial 0 |> should equal 1 + factorial 1 |> should equal 1 + factorial 5 |> should equal 120 + factorial 10 |> should equal 3628800 \ No newline at end of file diff --git a/semester4/HomeworkOne/HomeworkOne.Tests/Fibonacci.Tests.fs b/semester4/HomeworkOne/HomeworkOne.Tests/Fibonacci.Tests.fs new file mode 100644 index 0000000..b1a9ffb --- /dev/null +++ b/semester4/HomeworkOne/HomeworkOne.Tests/Fibonacci.Tests.fs @@ -0,0 +1,20 @@ +module Fibonacci.Tests + +open NUnit.Framework +open FsUnit +open Fibonacci +open System + +[] +let ``fibonacci with negative numbers`` () = + (fun() -> fibonacci -1 |> ignore) |> should throw typeof + (fun() -> fibonacci -10 |> ignore) |> should throw typeof + (fun() -> fibonacci -1242141 |> ignore) |> should throw typeof + +[] +let ``fibonacci with positive numbers`` () = + fibonacci 3 |> should equal 2 + fibonacci 0 |> should equal 0 + fibonacci 1 |> should equal 1 + fibonacci 5 |> should equal 5 + fibonacci 10 |> should equal 55 \ No newline at end of file diff --git a/semester4/HomeworkOne/HomeworkOne.Tests/FirstMath.Tests.fs b/semester4/HomeworkOne/HomeworkOne.Tests/FirstMath.Tests.fs new file mode 100644 index 0000000..c064f9f --- /dev/null +++ b/semester4/HomeworkOne/HomeworkOne.Tests/FirstMath.Tests.fs @@ -0,0 +1,14 @@ +module FirstMatch.Tests + +open NUnit.Framework +open FirstMatch + +[] +let firstMatchTest () = + Assert.AreEqual(None, firstMatch [] 1) + Assert.AreEqual(None, firstMatch [0; 24; 532] 1) + Assert.AreEqual(Some(0), firstMatch [0; 24; 532] 0) + Assert.AreEqual(Some(4), firstMatch [0; 24; 532; 2121; 1512] 1512) + Assert.AreEqual(Some(2), firstMatch [0; 24; 532; 2121; 1512] 532) + Assert.AreEqual(None, firstMatch ['a'; 'b'; 'c'; 'd'; 'e'; 'f'] 'g') + Assert.AreEqual(Some(3), firstMatch ['a'; 'b'; 'c'; 'd'; 'e'; 'f'] 'd') diff --git a/semester4/HomeworkOne/HomeworkOne.Tests/HomeworkOne.Tests.fsproj b/semester4/HomeworkOne/HomeworkOne.Tests/HomeworkOne.Tests.fsproj new file mode 100644 index 0000000..75ff444 --- /dev/null +++ b/semester4/HomeworkOne/HomeworkOne.Tests/HomeworkOne.Tests.fsproj @@ -0,0 +1,30 @@ + + + + netcoreapp3.1 + + false + false + + + + + + + + + + + + + + + + + + + + + + + diff --git a/semester4/HomeworkOne/HomeworkOne.Tests/ListOfPows.Tests.fs b/semester4/HomeworkOne/HomeworkOne.Tests/ListOfPows.Tests.fs new file mode 100644 index 0000000..e1f4cc4 --- /dev/null +++ b/semester4/HomeworkOne/HomeworkOne.Tests/ListOfPows.Tests.fs @@ -0,0 +1,12 @@ +module ListOfPows.Tests + +open NUnit.Framework +open ListOfPows + +[] +let listOfPowsTest () = + Assert.AreEqual([], listOfPows 2 1) + Assert.AreEqual([2], listOfPows 1 1) + Assert.AreEqual([], listOfPows -2 -1) + Assert.AreEqual([1; 2; 4], listOfPows 0 2) + Assert.AreEqual([16; 32; 64; 128; 256; 512; 1024; 2048; 4096], listOfPows 4 12) diff --git a/semester4/HomeworkOne/HomeworkOne.Tests/Program.fs b/semester4/HomeworkOne/HomeworkOne.Tests/Program.fs new file mode 100644 index 0000000..0695f84 --- /dev/null +++ b/semester4/HomeworkOne/HomeworkOne.Tests/Program.fs @@ -0,0 +1 @@ +module Program = let [] main _ = 0 diff --git a/semester4/HomeworkOne/HomeworkOne.Tests/ReverseList.Tests.fs b/semester4/HomeworkOne/HomeworkOne.Tests/ReverseList.Tests.fs new file mode 100644 index 0000000..e2fbf93 --- /dev/null +++ b/semester4/HomeworkOne/HomeworkOne.Tests/ReverseList.Tests.fs @@ -0,0 +1,12 @@ +module Reverse.Tests + +open NUnit.Framework +open ReverseList + +[] +let reverseTest () = + Assert.AreEqual([], listReverse []) + Assert.AreEqual([4], listReverse [4]) + Assert.AreEqual([5; 4], listReverse [4; 5]) + Assert.AreEqual([6; 6], listReverse [6; 6]) + Assert.AreEqual([1;2;3;4;5;6], listReverse [6;5;4;3;2;1]) \ No newline at end of file diff --git a/semester4/HomeworkOne/HomeworkOne.sln b/semester4/HomeworkOne/HomeworkOne.sln new file mode 100644 index 0000000..03a4241 --- /dev/null +++ b/semester4/HomeworkOne/HomeworkOne.sln @@ -0,0 +1,31 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.29926.136 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "HomeworkOne", "HomeworkOne\HomeworkOne.fsproj", "{E2CD7D3D-D25C-4007-A9D0-70BE0190EE11}" +EndProject +Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "HomeworkOne.Tests", "HomeworkOne.Tests\HomeworkOne.Tests.fsproj", "{273E452B-78D3-4282-990A-B7DE3A6747F0}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {E2CD7D3D-D25C-4007-A9D0-70BE0190EE11}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {E2CD7D3D-D25C-4007-A9D0-70BE0190EE11}.Debug|Any CPU.Build.0 = Debug|Any CPU + {E2CD7D3D-D25C-4007-A9D0-70BE0190EE11}.Release|Any CPU.ActiveCfg = Release|Any CPU + {E2CD7D3D-D25C-4007-A9D0-70BE0190EE11}.Release|Any CPU.Build.0 = Release|Any CPU + {273E452B-78D3-4282-990A-B7DE3A6747F0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {273E452B-78D3-4282-990A-B7DE3A6747F0}.Debug|Any CPU.Build.0 = Debug|Any CPU + {273E452B-78D3-4282-990A-B7DE3A6747F0}.Release|Any CPU.ActiveCfg = Release|Any CPU + {273E452B-78D3-4282-990A-B7DE3A6747F0}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {A1042F0E-6AC6-4E4E-9517-DE70CD40FE9A} + EndGlobalSection +EndGlobal diff --git a/semester4/HomeworkOne/HomeworkOne/Factorial.fs b/semester4/HomeworkOne/HomeworkOne/Factorial.fs new file mode 100644 index 0000000..a8f6219 --- /dev/null +++ b/semester4/HomeworkOne/HomeworkOne/Factorial.fs @@ -0,0 +1,14 @@ +module Factorial + +let factorial number = + let rec factorialHelper i acc = + if number < 0 then + invalidArg ("number") ("Negative numbers are not supported!") + else if number = 0 then + Some(1) + else if (number = i) then + Some(acc * number) + else + factorialHelper (i + 1) (acc * i) + + (factorialHelper 1 1).Value \ No newline at end of file diff --git a/semester4/HomeworkOne/HomeworkOne/Fibonacci.fs b/semester4/HomeworkOne/HomeworkOne/Fibonacci.fs new file mode 100644 index 0000000..7c6b178 --- /dev/null +++ b/semester4/HomeworkOne/HomeworkOne/Fibonacci.fs @@ -0,0 +1,14 @@ +module Fibonacci + +let fibonacci number = + let rec fibonacciHelper previous current i = + if number < 0 then + invalidArg ("number") ("Negative numbers are not supported!") + else if number = 0 then + Some(0) + else if number = i then + Some(current) + else + fibonacciHelper (current) (previous + current) (i + 1) + + (fibonacciHelper 0 1 1).Value \ No newline at end of file diff --git a/semester4/HomeworkOne/HomeworkOne/FirstMatch.fs b/semester4/HomeworkOne/HomeworkOne/FirstMatch.fs new file mode 100644 index 0000000..a51d6af --- /dev/null +++ b/semester4/HomeworkOne/HomeworkOne/FirstMatch.fs @@ -0,0 +1,11 @@ +module FirstMatch + +let firstMatch list toFind = + let rec firstMatchHelper list position = + if list = [] then + None + else if List.head list = toFind then + Some(position) + else + firstMatchHelper (List.tail list) (position + 1) + firstMatchHelper list 0 \ No newline at end of file diff --git a/semester4/HomeworkOne/HomeworkOne/HomeworkOne.fsproj b/semester4/HomeworkOne/HomeworkOne/HomeworkOne.fsproj new file mode 100644 index 0000000..e9f28a7 --- /dev/null +++ b/semester4/HomeworkOne/HomeworkOne/HomeworkOne.fsproj @@ -0,0 +1,16 @@ + + + + Library + netcoreapp3.1 + + + + + + + + + + + diff --git a/semester4/HomeworkOne/HomeworkOne/ListOfPows.fs b/semester4/HomeworkOne/HomeworkOne/ListOfPows.fs new file mode 100644 index 0000000..cdbd217 --- /dev/null +++ b/semester4/HomeworkOne/HomeworkOne/ListOfPows.fs @@ -0,0 +1,13 @@ +module ListOfPows + +open ReverseList + +let listOfPows n m = + let rec listOfPowsHelper list i currentPower = + if i < 0 then + [] + else if i > m then + list + else + listOfPowsHelper ((currentPower) :: list) (i + 1) (currentPower * 2) + listReverse (listOfPowsHelper [] n (pown 2 n)) \ No newline at end of file diff --git a/semester4/HomeworkOne/HomeworkOne/ReverseList.fs b/semester4/HomeworkOne/HomeworkOne/ReverseList.fs new file mode 100644 index 0000000..751a146 --- /dev/null +++ b/semester4/HomeworkOne/HomeworkOne/ReverseList.fs @@ -0,0 +1,10 @@ +module ReverseList + +let listReverse list = + let rec reverseHelper list reversedList = + if list = [] then + reversedList + else + reverseHelper (list.Tail) (list.Head :: reversedList) + + reverseHelper list [] \ No newline at end of file