Skip to content
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
16 changes: 16 additions & 0 deletions Test/Test.Test/MinInListTest.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
module Test.Test.MinInLisTest

open NUnit.Framework
open FsUnit
open Test.MinInList


[<Test>]
let minInListTest () =
let value = minInList [5; 2; 4; 5; 7; 3; 6; 2]
let value2 = minInList [5; 2; 4; 2; 7; 3; 6; 2]
let value3 = minInList [5; -2; 4; 5; 7; 3; 6; 2]

value |> should equal 2
value2 |> should equal 2
value3 |> should equal -2
27 changes: 27 additions & 0 deletions Test/Test.Test/Test.Test.fsproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>

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

<ItemGroup>
<Compile Include="TreeTest.fs" />
<Compile Include="MinInListTest.fs" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="FsUnit" Version="5.0.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.11.0" />
<PackageReference Include="NUnit" Version="3.13.3" />
<PackageReference Include="NUnit3TestAdapter" Version="4.0.0" />
<PackageReference Include="coverlet.collector" Version="3.1.0" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Test\Test.fsproj" />
</ItemGroup>

</Project>
19 changes: 19 additions & 0 deletions Test/Test.Test/TreeTest.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
module Test.Test.MinInListTest

open NUnit.Framework
open FsUnit
open Test.Tree

[<Test>]
let funcToTreeTest () =
let tree1 = Tree(3, Tip(4), Tip(61))
let tree2 = Tree(3, Tip(1), Tip(61))
let tree3 = Tree(2, Tip(4), Tip(61))

let list1 = funcToTree tree1 (fun x -> x % 2 = 0)
let list2 = funcToTree tree2 (fun x -> x % 2 = 0)
let list3 = funcToTree tree3 (fun x -> x % 2 = 0)

list1 |> should equal [4]
list2 |> should be Empty
list3 |> should equal [2; 4]
22 changes: 22 additions & 0 deletions Test/Test.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@

Microsoft Visual Studio Solution File, Format Version 12.00
Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "Test", "Test\Test.fsproj", "{63F86023-3284-4778-9ABD-566A7DF41900}"
EndProject
Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "Test.Test", "Test.Test\Test.Test.fsproj", "{B97C4599-9B6E-4E69-A457-E39934D08F63}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{63F86023-3284-4778-9ABD-566A7DF41900}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{63F86023-3284-4778-9ABD-566A7DF41900}.Debug|Any CPU.Build.0 = Debug|Any CPU
{63F86023-3284-4778-9ABD-566A7DF41900}.Release|Any CPU.ActiveCfg = Release|Any CPU
{63F86023-3284-4778-9ABD-566A7DF41900}.Release|Any CPU.Build.0 = Release|Any CPU
{B97C4599-9B6E-4E69-A457-E39934D08F63}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B97C4599-9B6E-4E69-A457-E39934D08F63}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B97C4599-9B6E-4E69-A457-E39934D08F63}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B97C4599-9B6E-4E69-A457-E39934D08F63}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
EndGlobal
11 changes: 11 additions & 0 deletions Test/Test/HashTable.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module Test.HashTable

open System
open Test

type public MyHashTable (func : Func<string, int>) =
let func element = func
let hash (element : string) = element |> func



5 changes: 5 additions & 0 deletions Test/Test/MinInList.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module Test.MinInList

// находит минимальный элемент списка
let minInList list =
(list |> List.map (fun x -> x * -1) |> List.max ) * -1
10 changes: 10 additions & 0 deletions Test/Test/Program.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
module Program

open Test.Tree


let tree = Tree(2, Tip(4), Tree(3, Tree(6, Tip(5), Tip(8)), Tip(1)))

let newTree = funcToTree tree (fun x -> x % 2 = 0)

printf $"{funcToTree tree (fun x -> x % 2 = 0)}"
16 changes: 16 additions & 0 deletions Test/Test/Test.fsproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<DockerDefaultTargetOS>Windows</DockerDefaultTargetOS>
</PropertyGroup>

<ItemGroup>
<Compile Include="MinInList.fs" />
<Compile Include="Tree.fs" />
<Compile Include="Program.fs" />
<Compile Include="HashTable.fs" />
</ItemGroup>

</Project>
18 changes: 18 additions & 0 deletions Test/Test/Tree.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
module Test.Tree

type Tree<'a> =
| Tree of 'a * Tree<'a> * Tree<'a>
| Tip of 'a

// функция, которая применяет функцию к каждому элементу дерева
let funcToTree tree func =
let check value func list =
if func value then value :: list else
list
let rec findElement tree func list =
match tree with
| Tip value -> check value func list
| Tree (value, left, right) ->

(check value func list) @ findElement left func [] @ findElement right func []
findElement tree func []