Skip to content
Snippets Groups Projects
Commit 3dacfcf4 authored by Vesa Lappalainen's avatar Vesa Lappalainen :bicyclist:
Browse files

matka

parent 664cacfc
No related branches found
No related tags found
No related merge requests found
......@@ -5,6 +5,7 @@
<projectFile>KaannaTaulukkoAli/KaannaTaulukkoAli.csproj</projectFile>
<projectFile>Laskuja/Laskuja.csproj</projectFile>
<projectFile>LumiukkoAli/LumiukkoAli.csproj</projectFile>
<projectFile>Matka/Matka.csproj</projectFile>
</component>
<component name="AutoImportSettings">
<option name="autoReloadType" value="SELECTIVE" />
......@@ -12,6 +13,7 @@
<component name="ChangeListManager">
<list default="true" id="fc85cdb2-6a04-4042-bd67-bd7da4e7a5a1" name="Changes" comment="">
<change beforePath="$PROJECT_DIR$/.idea/.idea.luento05/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/.idea.luento05/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/KaannaTaulukkoAli/KaannaTaulukkoAli.cs" beforeDir="false" afterPath="$PROJECT_DIR$/KaannaTaulukkoAli/KaannaTaulukkoAli.cs" afterDir="false" />
<change beforePath="$PROJECT_DIR$/luento05.sln" beforeDir="false" afterPath="$PROJECT_DIR$/luento05.sln" afterDir="false" />
</list>
<option name="SHOW_DIALOG" value="false" />
......@@ -37,7 +39,9 @@
"keyToString": {
"RunOnceActivity.OpenProjectViewOnStart": "true",
"RunOnceActivity.ShowReadmeOnStart": "true",
"ToolWindowUnit Tests Coverage.ShowToolbar": "false",
"WebServerToolWindowFactoryState": "false",
"XThreadsFramesViewSplitterKey": "0.23977695",
"git-widget-placeholder": "main",
"node.js.detected.package.eslint": "true",
"node.js.detected.package.tslint": "true",
......@@ -54,7 +58,7 @@
]
}
}]]></component>
<component name="RunManager" selected=".NET Project.LumiukkoAli">
<component name="RunManager" selected=".NET Project.Matka">
<configuration name="KaannaTaulukko" type="DotNetProject" factoryName=".NET Project">
<option name="EXE_PATH" value="" />
<option name="PROGRAM_PARAMETERS" value="" />
......@@ -127,6 +131,24 @@
<option name="Build" />
</method>
</configuration>
<configuration name="Matka" type="DotNetProject" factoryName=".NET Project">
<option name="EXE_PATH" value="" />
<option name="PROGRAM_PARAMETERS" value="" />
<option name="WORKING_DIRECTORY" value="" />
<option name="PASS_PARENT_ENVS" value="1" />
<option name="USE_EXTERNAL_CONSOLE" value="0" />
<option name="USE_MONO" value="0" />
<option name="RUNTIME_ARGUMENTS" value="" />
<option name="PROJECT_PATH" value="$PROJECT_DIR$/Matka/Matka.csproj" />
<option name="PROJECT_EXE_PATH_TRACKING" value="1" />
<option name="PROJECT_ARGUMENTS_TRACKING" value="1" />
<option name="PROJECT_WORKING_DIRECTORY_TRACKING" value="1" />
<option name="PROJECT_KIND" value="DotNetCore" />
<option name="PROJECT_TFM" value="" />
<method v="2">
<option name="Build" />
</method>
</configuration>
</component>
<component name="SpellCheckerSettings" RuntimeDictionaries="0" Folders="0" CustomDictionaries="0" DefaultDictionary="application-level" UseSingleDictionary="true" transferred="true" />
<component name="TaskManager">
......@@ -136,14 +158,43 @@
<option name="number" value="Default" />
<option name="presentableId" value="Default" />
<updated>1694811079122</updated>
<workItem from="1694811080272" duration="3393000" />
<workItem from="1694811080272" duration="10304000" />
</task>
<servers />
</component>
<component name="TypeScriptGeneratedFilesManager">
<option name="version" value="3" />
</component>
<component name="UnitTestsCoverage.Settings">
<option name="coveragePercentColumnWidth" value="52" />
<option name="sortOrder" value="DESCENDING" />
<option name="sortedColumn" value="1" />
<option name="symbolColumnWidth" value="31" />
<coverage-tree-state>
<expand />
<select />
</coverage-tree-state>
</component>
<component name="VcsManagerConfiguration">
<option name="CLEAR_INITIAL_COMMIT_MESSAGE" value="true" />
</component>
<component name="XDebuggerManager">
<breakpoint-manager>
<breakpoints>
<line-breakpoint enabled="true" type="DotNet Breakpoints">
<url>file://$PROJECT_DIR$/KaannaTaulukkoAli/KaannaTaulukkoAli.cs</url>
<line>52</line>
<properties documentPath="E:\kurssit\ohj1\esimerkit\2023s\luennot\luento05\KaannaTaulukkoAli\KaannaTaulukkoAli.cs" initialLine="52" containingFunctionPresentation="Method 'Vaihda'">
<startOffsets>
<option value="1613" />
</startOffsets>
<endOffsets>
<option value="1621" />
</endOffsets>
</properties>
<option name="timeStamp" value="1" />
</line-breakpoint>
</breakpoints>
</breakpoint-manager>
</component>
</project>
\ No newline at end of file
......@@ -16,20 +16,20 @@ public class KaannaTaulukkoAli
Vaihda(t, 0, 5);
Vaihda(t, 1, 4);
Vaihda(t, 2, 3);
Console.WriteLine(String.Join(", ", t));
Console.WriteLine(string.Join(", ", t));
// Seuraava ei toimisi Javassa:
Vaihda(ref t[0], ref t[5]);
Vaihda(ref t[1], ref t[4]);
Vaihda(ref t[2], ref t[3]);
Console.WriteLine(String.Join(", ", t));
Console.WriteLine(string.Join(", ", t));
// Silmukoilla
for (int i1 = 0, i2 = t.Length-1; i1 < i2; i1++, i2--) Vaihda(t, i1, i2);
Console.WriteLine(String.Join(", ", t));
Console.WriteLine(string.Join(", ", t));
for (int i1 = 0, i2 = t.Length-1; i1 < i2; i1++, i2--) Vaihda(ref t[i1], ref t[i2]);
Console.WriteLine(String.Join(", ", t));
Console.WriteLine(string.Join(", ", t));
}
......@@ -37,15 +37,15 @@ public class KaannaTaulukkoAli
/// Vaihedetaan taulukon kahden alkion paikka keskenään
/// </summary>
/// <param name="t">taulukko josta vaihdetaan</param>
/// <param name="i">ensimmäsien vaihdettavan alkion indeksi</param>
/// <param name="i">ensimmäisen vaihdettavan alkion indeksi</param>
/// <param name="j">toisen vaihdettavan alkion indeksi</param>
/// <example>
/// <pre name="test">
/// int[] t = { 23, 45, 12, 66 };
/// Vaihda(t,0,2);
/// String.Join(" ", t) === "12 45 23 66";
/// string.Join(" ", t) === "12 45 23 66";
/// Vaihda(t,0,3);
/// String.Join(" ", t) === "66 45 23 12";
/// string.Join(" ", t) === "66 45 23 12";
/// </pre>
/// </example>
public static void Vaihda(int[] t, int i, int j)
......@@ -69,7 +69,7 @@ public class KaannaTaulukkoAli
/// a === 5; b === 3;
/// int[] t = { 23, 45, 12, 66 };
/// Vaihda(ref t[0], ref t[2]);
/// String.Join(" ", t) === "12 45 23 66";
/// string.Join(" ", t) === "12 45 23 66";
/// </pre>
/// </example>
public static void Vaihda(ref int a, ref int b)
......
using System;
using NUnit.Framework;
using static KaannaTaulukkoAli;
[TestFixture]
[DefaultFloatingPointTolerance(0.000001)]
public class TestKaannaTaulukkoAli
{
[Test]
public void TestVaihda43()
{
int[] t = { 23, 45, 12, 66 };
Vaihda(t,0,2);
Assert.AreEqual( "12 45 23 66", string.Join(" ", t) , "in method Vaihda, line 46");
Vaihda(t,0,3);
Assert.AreEqual( "66 45 23 12", string.Join(" ", t) , "in method Vaihda, line 48");
}
[Test]
public void TestVaihda66()
{
int a=3, b=5;
Vaihda(ref a, ref b);
Assert.AreEqual( 5, a , "in method Vaihda, line 69");;
;
;
;
;
Assert.AreEqual( 3, b , "in method Vaihda, line 69");
int[] t = { 23, 45, 12, 66 };
Vaihda(ref t[0], ref t[2]);
Assert.AreEqual( "12 45 23 66", string.Join(" ", t) , "in method Vaihda, line 72");
}
}
<?xml version="1.0" encoding="UTF-8"?>
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<IsPackable>false</IsPackable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="NUnit" Version="3.13.1"/>
<PackageReference Include="NUnit3TestAdapter" Version="3.17.0"/>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.8.3"/>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\KaannaTaulukkoAli\KaannaTaulukkoAli.csproj"/>
</ItemGroup>
</Project>
using System;
/// @author vesal
/// @version 15.9.2014
/// <summary>
///
/// </summary>
public class Matka
{
/// <summary>
/// Lasketan kaunako menee kotoa töihin
/// </summary>
public static void Main()
{
double matkaKm = 9.7;
double nopeusKmh = 25.0;
// double aika = matkaKm / nopeusKmh;
double aika = LaskeAika(matkaKm, nopeusKmh);
string saika;
saika = AikaJonoksi(aika);
Console.WriteLine(saika);
}
/// <summary>
/// Muutetaan tunteina oleva aika merkkijonoksi
/// </summary>
/// <param name="t">aika tunteina</param>
/// <returns>aika merkkijonona</returns>
/// <example>
/// <pre name="test">
/// AikaJonoksi(0) === "0:00:00";
/// AikaJonoksi(1) === "1:00:00";
/// AikaJonoksi(0.5) === "0:30:00";
/// AikaJonoksi(0.25) === "0:15:00";
/// </pre>
/// </example>
public static string AikaJonoksi(double t)
{
return "0:00:00";
}
/// <summary>
/// Funktiolla lasketaan kauanko aikaa menee tiettyyn matkaan tietyllä nopeudella
/// </summary>
/// <param name="s">matka km</param>
/// <param name="v">nopeus (vauhti) km/h</param>
/// <returns>matkaan kulunut aika tunteina</returns>
/// <example>
/// <pre name="test">
/// LaskeAika(20, 40) ~~~ 0.5;
/// LaskeAika(100, 50) ~~~ 2.0;
/// </pre>
/// </example>
public static double LaskeAika(double s, double v)
{
double tulos;
tulos = s / v;
return tulos;
}
}
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net7.0</TargetFramework>
<ExternalConsole>true</ExternalConsole>
</PropertyGroup>
</Project>
using System;
using NUnit.Framework;
using static Matka;
[TestFixture]
[DefaultFloatingPointTolerance(0.000001)]
public class TestMatka
{
[Test]
public void TestAikaJonoksi30()
{
Assert.AreEqual( "0:00:00", AikaJonoksi(0) , "in method AikaJonoksi, line 31");
Assert.AreEqual( "1:00:00", AikaJonoksi(1) , "in method AikaJonoksi, line 32");
Assert.AreEqual( "0:30:00", AikaJonoksi(0.5) , "in method AikaJonoksi, line 33");
Assert.AreEqual( "0:15:00", AikaJonoksi(0.25) , "in method AikaJonoksi, line 34");
}
[Test]
public void TestLaskeAika50()
{
Assert.AreEqual( 0.5, LaskeAika(20, 40) , 0.000001, "in method LaskeAika, line 51");
Assert.AreEqual( 2.0, LaskeAika(100, 50) , 0.000001, "in method LaskeAika, line 52");
}
}
<?xml version="1.0" encoding="UTF-8"?>
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<IsPackable>false</IsPackable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="NUnit" Version="3.13.1"/>
<PackageReference Include="NUnit3TestAdapter" Version="3.17.0"/>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.8.3"/>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Matka\Matka.csproj"/>
</ItemGroup>
</Project>
......@@ -11,31 +11,49 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "KaannaTaulukkoAli", "Kaanna
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LumiukkoAli", "LumiukkoAli\LumiukkoAli.csproj", "{D673A206-F619-4DE4-8D9E-9BC97D3F3403}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "KaannaTaulukkoAliTest", "KaannaTaulukkoAliTest\KaannaTaulukkoAliTest.csproj", "{C7CDCB02-B3E1-4796-A358-ACCF6DD4E70F}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Matka", "Matka\Matka.csproj", "{2A075536-7A2E-4269-B90D-2D3B3FD6ADAC}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MatkaTest", "MatkaTest\MatkaTest.csproj", "{479DDDC3-F358-4AF7-8978-C26ABD4193A9}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{8795F3DE-3634-4EAC-ADA8-C3711D85DE5E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{8795F3DE-3634-4EAC-ADA8-C3711D85DE5E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{8795F3DE-3634-4EAC-ADA8-C3711D85DE5E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{8795F3DE-3634-4EAC-ADA8-C3711D85DE5E}.Release|Any CPU.Build.0 = Release|Any CPU
{1FF97298-9EFD-4C3A-A236-D81632A55E31}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{1FF97298-9EFD-4C3A-A236-D81632A55E31}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1FF97298-9EFD-4C3A-A236-D81632A55E31}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1FF97298-9EFD-4C3A-A236-D81632A55E31}.Release|Any CPU.Build.0 = Release|Any CPU
{DDD0109C-AA3F-4A41-8319-62FF01D3C9AA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{DDD0109C-AA3F-4A41-8319-62FF01D3C9AA}.Debug|Any CPU.Build.0 = Debug|Any CPU
{DDD0109C-AA3F-4A41-8319-62FF01D3C9AA}.Release|Any CPU.ActiveCfg = Release|Any CPU
{DDD0109C-AA3F-4A41-8319-62FF01D3C9AA}.Release|Any CPU.Build.0 = Release|Any CPU
{C53450B9-0A47-4BA7-93A7-9CD443C0B3E1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C53450B9-0A47-4BA7-93A7-9CD443C0B3E1}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C53450B9-0A47-4BA7-93A7-9CD443C0B3E1}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C53450B9-0A47-4BA7-93A7-9CD443C0B3E1}.Release|Any CPU.Build.0 = Release|Any CPU
{D673A206-F619-4DE4-8D9E-9BC97D3F3403}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D673A206-F619-4DE4-8D9E-9BC97D3F3403}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D673A206-F619-4DE4-8D9E-9BC97D3F3403}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D673A206-F619-4DE4-8D9E-9BC97D3F3403}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{8795F3DE-3634-4EAC-ADA8-C3711D85DE5E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{8795F3DE-3634-4EAC-ADA8-C3711D85DE5E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{8795F3DE-3634-4EAC-ADA8-C3711D85DE5E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{8795F3DE-3634-4EAC-ADA8-C3711D85DE5E}.Release|Any CPU.Build.0 = Release|Any CPU
{1FF97298-9EFD-4C3A-A236-D81632A55E31}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{1FF97298-9EFD-4C3A-A236-D81632A55E31}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1FF97298-9EFD-4C3A-A236-D81632A55E31}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1FF97298-9EFD-4C3A-A236-D81632A55E31}.Release|Any CPU.Build.0 = Release|Any CPU
{DDD0109C-AA3F-4A41-8319-62FF01D3C9AA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{DDD0109C-AA3F-4A41-8319-62FF01D3C9AA}.Debug|Any CPU.Build.0 = Debug|Any CPU
{DDD0109C-AA3F-4A41-8319-62FF01D3C9AA}.Release|Any CPU.ActiveCfg = Release|Any CPU
{DDD0109C-AA3F-4A41-8319-62FF01D3C9AA}.Release|Any CPU.Build.0 = Release|Any CPU
{C53450B9-0A47-4BA7-93A7-9CD443C0B3E1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C53450B9-0A47-4BA7-93A7-9CD443C0B3E1}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C53450B9-0A47-4BA7-93A7-9CD443C0B3E1}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C53450B9-0A47-4BA7-93A7-9CD443C0B3E1}.Release|Any CPU.Build.0 = Release|Any CPU
{D673A206-F619-4DE4-8D9E-9BC97D3F3403}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D673A206-F619-4DE4-8D9E-9BC97D3F3403}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D673A206-F619-4DE4-8D9E-9BC97D3F3403}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D673A206-F619-4DE4-8D9E-9BC97D3F3403}.Release|Any CPU.Build.0 = Release|Any CPU
{C7CDCB02-B3E1-4796-A358-ACCF6DD4E70F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C7CDCB02-B3E1-4796-A358-ACCF6DD4E70F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C7CDCB02-B3E1-4796-A358-ACCF6DD4E70F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C7CDCB02-B3E1-4796-A358-ACCF6DD4E70F}.Release|Any CPU.Build.0 = Release|Any CPU
{2A075536-7A2E-4269-B90D-2D3B3FD6ADAC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2A075536-7A2E-4269-B90D-2D3B3FD6ADAC}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2A075536-7A2E-4269-B90D-2D3B3FD6ADAC}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2A075536-7A2E-4269-B90D-2D3B3FD6ADAC}.Release|Any CPU.Build.0 = Release|Any CPU
{479DDDC3-F358-4AF7-8978-C26ABD4193A9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{479DDDC3-F358-4AF7-8978-C26ABD4193A9}.Debug|Any CPU.Build.0 = Debug|Any CPU
{479DDDC3-F358-4AF7-8978-C26ABD4193A9}.Release|Any CPU.ActiveCfg = Release|Any CPU
{479DDDC3-F358-4AF7-8978-C26ABD4193A9}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
EndGlobal
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment