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

poista bak

parent 9c4a6260
No related branches found
No related tags found
No related merge requests found
......@@ -14,10 +14,26 @@ public class Poikkeus
{
int[] luvut = { 2, 4, 1 };
int s = Summa(luvut, 0, 4);
int a1 = 3, a2 = 4, a3 = 0, a4 = 7;
Console.WriteLine(s);
try
{
int s = Summa(luvut, 0, 2);
Console.WriteLine(s);
Console.WriteLine(10 / a1);
Console.WriteLine(10 / a2);
Console.WriteLine(10 / a3);
Console.WriteLine(10 / a4);
}
catch (IndexOutOfRangeException ex)
{
Console.WriteLine(ex.Message);
}
catch (DivideByZeroException )
{
Console.WriteLine("Jaoit 0:lla ääliö!");
}
}
......
using System;
using NUnit.Framework;
using static Poikkeus;
[TestFixture]
[DefaultFloatingPointTolerance(0.000001)]
public class TestPoikkeus
{
[Test]
public void TestSumma49()
{
int[] luvut = { 2, 4, 1 };
Assert.AreEqual( 7, Summa(luvut) , "in method Summa, line 51");
Assert.AreEqual( 7, Summa(luvut,0,2) , "in method Summa, line 52");
Assert.AreEqual( 5, Summa(luvut,1,2) , "in method Summa, line 53");
Assert.AreEqual( 5, Summa(luvut,1) , "in method Summa, line 54");
Assert.AreEqual( 6, Summa(luvut,0,1) , "in method Summa, line 55");
Assert.AreEqual( 4, Summa(luvut,1,1) , "in method Summa, line 56");
try
{
Assert.AreEqual( 0, Summa(luvut,1,0) , "in method Summa, line 57");
Assert.Fail("Did not throw IndexOutOfRangeException in method Summa on line 56");
}
catch (IndexOutOfRangeException)
{
}
try
{
Assert.AreEqual( 7, Summa(luvut,0,100) , "in method Summa, line 58");
Assert.Fail("Did not throw IndexOutOfRangeException in method Summa on line 57");
}
catch (IndexOutOfRangeException)
{
}
try
{
Assert.AreEqual( 7, Summa(luvut,-4,100) , "in method Summa, line 59");
Assert.Fail("Did not throw IndexOutOfRangeException in method Summa on line 58");
}
catch (IndexOutOfRangeException)
{
}
}
}
<?xml version="1.0" encoding="UTF-8"?><Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.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="..\Poikkeus\Poikkeus.csproj"/>
</ItemGroup>
</Project>
......@@ -15,10 +15,22 @@ public class Poistot
/// </summary>
public static void Main()
{
List<string> sanat = new List<string>() { "kissa", "koira", "kana", "susi", "ankka" };
List<string> sanat = new List<string>() { "kissa", "", "koira", "kana", "susi", "ankka" };
Console.WriteLine(String.Join(" ", sanat));
// sanat.RemoveAll(delegate (string sana) { return sana == "susi"; });
// sanat.RemoveAll(delegate (string sana) { return sana == "kana"; });
// sanat.RemoveAll(sana => sana == "kana");
sanat.RemoveAll(sana => sana.CompareTo("kana") <= 0);
Console.WriteLine(String.Join(" ", sanat));
}
public static bool AlkaaKlla(string sana)
{
if (sana.Length == 0) return false;
return sana[0] == 'k';
}
}
......@@ -22,11 +22,19 @@ public class TiedostoIsoksi
string nimi = "kissa.txt";
if (args.Length > 0) nimi = args[0];
string[] luetutRivit = File.ReadAllLines(nimi);
foreach (string rivi in luetutRivit)
// onko tiedostoa
try
{
string[] luetutRivit = File.ReadAllLines(nimi);
foreach (string rivi in luetutRivit)
{
Console.WriteLine(rivi.ToUpper());
}
}
catch (FileNotFoundException ex)
{
Console.WriteLine(rivi.ToUpper());
// Console.WriteLine(ex.Message);
Console.WriteLine("Ei löyvy: " + nimi);
}
}
......
kissa
kana
koira
mato
kana
......@@ -7,6 +7,10 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Poistot", "Poistot\Poistot.
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Poikkeus", "Poikkeus\Poikkeus.csproj", "{5FB72467-CC42-4593-A68A-6C5B7C72FA86}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TiedostoIsoksi", "TiedostoIsoksi\TiedostoIsoksi.csproj", "{D9F6B6FA-0A72-4834-A55A-D46750902390}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PoikkeusTest", "PoikkeusTest\PoikkeusTest.csproj", "{391A0206-EBC6-4D22-9CC3-9E9067A425EA}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
......@@ -21,6 +25,14 @@ Global
{5FB72467-CC42-4593-A68A-6C5B7C72FA86}.Debug|Any CPU.Build.0 = Debug|Any CPU
{5FB72467-CC42-4593-A68A-6C5B7C72FA86}.Release|Any CPU.ActiveCfg = Release|Any CPU
{5FB72467-CC42-4593-A68A-6C5B7C72FA86}.Release|Any CPU.Build.0 = Release|Any CPU
{D9F6B6FA-0A72-4834-A55A-D46750902390}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D9F6B6FA-0A72-4834-A55A-D46750902390}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D9F6B6FA-0A72-4834-A55A-D46750902390}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D9F6B6FA-0A72-4834-A55A-D46750902390}.Release|Any CPU.Build.0 = Release|Any CPU
{391A0206-EBC6-4D22-9CC3-9E9067A425EA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{391A0206-EBC6-4D22-9CC3-9E9067A425EA}.Debug|Any CPU.Build.0 = Debug|Any CPU
{391A0206-EBC6-4D22-9CC3-9E9067A425EA}.Release|Any CPU.ActiveCfg = Release|Any CPU
{391A0206-EBC6-4D22-9CC3-9E9067A425EA}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
......
This diff is collapsed.
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