Initial commit

This commit is contained in:
KäseToatz
2024-10-16 21:34:23 +02:00
commit 8d5e03d0df
9 changed files with 651 additions and 0 deletions

3
.gitignore vendored Normal file
View File

@ -0,0 +1,3 @@
/.vs
bin
obj

34
BAI2.sln Normal file
View File

@ -0,0 +1,34 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.30104.148
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BAI2", "BAI2\BAI2.csproj", "{83B66ABE-FB78-437F-B84B-96723C48A503}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tests", "Tests\Tests.csproj", "{6F24AABC-715B-4DCC-9954-7EE335CC643D}"
ProjectSection(ProjectDependencies) = postProject
{83B66ABE-FB78-437F-B84B-96723C48A503} = {83B66ABE-FB78-437F-B84B-96723C48A503}
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{83B66ABE-FB78-437F-B84B-96723C48A503}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{83B66ABE-FB78-437F-B84B-96723C48A503}.Debug|Any CPU.Build.0 = Debug|Any CPU
{83B66ABE-FB78-437F-B84B-96723C48A503}.Release|Any CPU.ActiveCfg = Release|Any CPU
{83B66ABE-FB78-437F-B84B-96723C48A503}.Release|Any CPU.Build.0 = Release|Any CPU
{6F24AABC-715B-4DCC-9954-7EE335CC643D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{6F24AABC-715B-4DCC-9954-7EE335CC643D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6F24AABC-715B-4DCC-9954-7EE335CC643D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6F24AABC-715B-4DCC-9954-7EE335CC643D}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {C0AC49A3-CED8-4A05-A825-FCEAD2A8D369}
EndGlobalSection
EndGlobal

9
BAI2/BAI2.csproj Normal file
View File

@ -0,0 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<RootNamespace>BAI</RootNamespace>
</PropertyGroup>
</Project>

158
BAI2/Program.cs Normal file
View File

@ -0,0 +1,158 @@
using System;
using System.Collections.Generic;
namespace BAI
{
public partial class BAI_Afteken2
{
public static bool Vooruit(uint b)
{
return ((b >> 7) & 1) == 1;
}
public static uint Vermogen(uint b)
{
return (uint)Math.Round(100.0 / 3.0 * ((b >> 5) & 0b11));
}
public static bool Wagon(uint b)
{
return ((b >> 4) & 1) == 1;
}
public static bool Licht(uint b)
{
return ((b >> 3) & 1) == 1;
}
public static uint ID(uint b)
{
return b & 0b111;
}
public static HashSet<uint> Alle(List<uint> inputStroom)
{
HashSet<uint> set = [];
set.UnionWith(inputStroom);
return set;
}
public static HashSet<uint> ZonderLicht(List<uint> inputStroom)
{
HashSet<uint> set = [];
foreach (uint b in inputStroom)
{
if (!Licht(b))
{
set.Add(b);
}
}
return set;
}
public static HashSet<uint> MetWagon(List<uint> inputStroom)
{
HashSet<uint> set = [];
foreach (uint b in inputStroom)
{
if (Wagon(b))
{
set.Add(b);
}
}
return set;
}
public static HashSet<uint> SelecteerID(List<uint> inputStroom, uint lower, uint upper)
{
HashSet<uint> set = [];
foreach (uint b in inputStroom)
{
uint id = ID(b);
if (id >= lower && id <= upper)
{
set.Add(b);
}
}
return set;
}
public static HashSet<uint> Opdr3a(List<uint> inputStroom)
{
HashSet<uint> set = SelecteerID(inputStroom, 0, 2);
set.IntersectWith(ZonderLicht(inputStroom));
return set;
}
public static HashSet<uint> Opdr3b(List<uint> inputStroom)
{
HashSet<uint> set = Alle(inputStroom);
set.ExceptWith(Opdr3a(inputStroom));
return set;
}
public static void ToonInfo(uint b)
{
Console.WriteLine($"ID {ID(b)}, Licht {Licht(b)}, Wagon {Wagon(b)}, Vermogen {Vermogen(b)}, Vooruit {Vooruit(b)}");
}
public static List<uint> GetInputStroom()
{
List<uint> inputStream = new List<uint>();
for (uint i = 0; i < 256; i++)
{
inputStream.Add(i);
}
return inputStream;
}
public static void PrintSet(HashSet<uint> x)
{
Console.Write("{");
foreach (uint i in x)
Console.Write($" {i}");
Console.WriteLine($" }} ({x.Count} elementen)");
}
static void Main(string[] args)
{
Console.WriteLine("=== Opgave 1 ===");
ToonInfo(210);
Console.WriteLine();
List<uint> inputStroom = GetInputStroom();
Console.WriteLine("=== Opgave 2 ===");
HashSet<uint> alle = Alle(inputStroom);
PrintSet(alle);
HashSet<uint> zonderLicht = ZonderLicht(inputStroom);
PrintSet(zonderLicht);
HashSet<uint> metWagon = MetWagon(inputStroom);
PrintSet(metWagon);
HashSet<uint> groter6 = SelecteerID(inputStroom, 6, 7);
PrintSet(groter6);
Console.WriteLine();
Console.WriteLine("=== Opgave 3a ===");
HashSet<uint> opg3a = Opdr3a(inputStroom);
PrintSet(opg3a);
foreach (uint b in opg3a)
{
ToonInfo(b);
}
Console.WriteLine();
Console.WriteLine("=== Opgave 3b ===");
HashSet<uint> opg3b = Opdr3b(inputStroom);
PrintSet(opg3b);
foreach (uint b in opg3b)
{
ToonInfo(b);
}
Console.WriteLine();
}
}
}

250
Tests/Opdr1Tests.cs Normal file
View File

@ -0,0 +1,250 @@
using NUnit.Framework;
namespace BAI
{
[TestFixture]
public class Opdr1Tests
{
[TestCase((uint)1, (uint)1)]
[TestCase((uint)8, (uint)0)]
[TestCase((uint)18, (uint)2)]
[TestCase((uint)21, (uint)5)]
[TestCase((uint)34, (uint)2)]
[TestCase((uint)35, (uint)3)]
[TestCase((uint)47, (uint)7)]
[TestCase((uint)52, (uint)4)]
[TestCase((uint)60, (uint)4)]
[TestCase((uint)69, (uint)5)]
[TestCase((uint)73, (uint)1)]
[TestCase((uint)86, (uint)6)]
[TestCase((uint)99, (uint)3)]
[TestCase((uint)103, (uint)7)]
[TestCase((uint)112, (uint)0)]
[TestCase((uint)120, (uint)0)]
[TestCase((uint)125, (uint)5)]
[TestCase((uint)137, (uint)1)]
[TestCase((uint)138, (uint)2)]
[TestCase((uint)151, (uint)7)]
[TestCase((uint)154, (uint)2)]
[TestCase((uint)164, (uint)4)]
[TestCase((uint)171, (uint)3)]
[TestCase((uint)177, (uint)1)]
[TestCase((uint)188, (uint)4)]
[TestCase((uint)190, (uint)6)]
[TestCase((uint)203, (uint)3)]
[TestCase((uint)205, (uint)5)]
[TestCase((uint)216, (uint)0)]
[TestCase((uint)222, (uint)6)]
[TestCase((uint)229, (uint)5)]
[TestCase((uint)239, (uint)7)]
[TestCase((uint)242, (uint)2)]
[TestCase((uint)255, (uint)7)]
public void Bit012_ID(uint b, uint expected)
{
// Act
uint actual = BAI_Afteken2.ID(b);
// Assert
Assert.AreEqual(expected, actual);
}
[TestCase((uint)1, false)]
[TestCase((uint)8, true)]
[TestCase((uint)18, false)]
[TestCase((uint)21, false)]
[TestCase((uint)34, false)]
[TestCase((uint)35, false)]
[TestCase((uint)47, true)]
[TestCase((uint)52, false)]
[TestCase((uint)60, true)]
[TestCase((uint)69, false)]
[TestCase((uint)73, true)]
[TestCase((uint)86, false)]
[TestCase((uint)99, false)]
[TestCase((uint)103, false)]
[TestCase((uint)112, false)]
[TestCase((uint)120, true)]
[TestCase((uint)125, true)]
[TestCase((uint)137, true)]
[TestCase((uint)138, true)]
[TestCase((uint)151, false)]
[TestCase((uint)154, true)]
[TestCase((uint)164, false)]
[TestCase((uint)171, true)]
[TestCase((uint)177, false)]
[TestCase((uint)188, true)]
[TestCase((uint)190, true)]
[TestCase((uint)203, true)]
[TestCase((uint)205, true)]
[TestCase((uint)216, true)]
[TestCase((uint)222, true)]
[TestCase((uint)229, false)]
[TestCase((uint)239, true)]
[TestCase((uint)242, false)]
[TestCase((uint)255, true)]
public void Bit3_Licht(uint b, bool expected)
{
// Act
bool actual = BAI_Afteken2.Licht(b);
// Assert
Assert.AreEqual(expected, actual);
}
[TestCase((uint)1, false)]
[TestCase((uint)8, false)]
[TestCase((uint)18, true)]
[TestCase((uint)21, true)]
[TestCase((uint)34, false)]
[TestCase((uint)35, false)]
[TestCase((uint)47, false)]
[TestCase((uint)52, true)]
[TestCase((uint)60, true)]
[TestCase((uint)69, false)]
[TestCase((uint)73, false)]
[TestCase((uint)86, true)]
[TestCase((uint)99, false)]
[TestCase((uint)103, false)]
[TestCase((uint)112, true)]
[TestCase((uint)120, true)]
[TestCase((uint)125, true)]
[TestCase((uint)137, false)]
[TestCase((uint)138, false)]
[TestCase((uint)151, true)]
[TestCase((uint)154, true)]
[TestCase((uint)164, false)]
[TestCase((uint)171, false)]
[TestCase((uint)177, true)]
[TestCase((uint)188, true)]
[TestCase((uint)190, true)]
[TestCase((uint)203, false)]
[TestCase((uint)205, false)]
[TestCase((uint)216, true)]
[TestCase((uint)222, true)]
[TestCase((uint)229, false)]
[TestCase((uint)239, false)]
[TestCase((uint)242, true)]
[TestCase((uint)255, true)]
public void Bit4_Wagon(uint b, bool expected)
{
// Act
bool actual = BAI_Afteken2.Wagon(b);
// Assert
Assert.AreEqual(expected, actual);
}
[TestCase((uint)1, 0)]
[TestCase((uint)8, 0)]
[TestCase((uint)18, 0)]
[TestCase((uint)21, 0)]
[TestCase((uint)34, 33)]
[TestCase((uint)35, 33)]
[TestCase((uint)47, 33)]
[TestCase((uint)52, 33)]
[TestCase((uint)60, 33)]
[TestCase((uint)69, 67)]
[TestCase((uint)73, 67)]
[TestCase((uint)86, 67)]
[TestCase((uint)99, 100)]
[TestCase((uint)103, 100)]
[TestCase((uint)112, 100)]
[TestCase((uint)120, 100)]
[TestCase((uint)125, 100)]
[TestCase((uint)137, 0)]
[TestCase((uint)138, 0)]
[TestCase((uint)151, 0)]
[TestCase((uint)154, 0)]
[TestCase((uint)164, 33)]
[TestCase((uint)171, 33)]
[TestCase((uint)177, 33)]
[TestCase((uint)188, 33)]
[TestCase((uint)190, 33)]
[TestCase((uint)203, 67)]
[TestCase((uint)205, 67)]
[TestCase((uint)216, 67)]
[TestCase((uint)222, 67)]
[TestCase((uint)229, 100)]
[TestCase((uint)239, 100)]
[TestCase((uint)242, 100)]
[TestCase((uint)255, 100)]
public void Bit56_Vermogen(uint b, int expected)
{
// Act
uint actual = BAI_Afteken2.Vermogen(b);
// Assert
Assert.AreEqual(expected, actual);
}
[TestCase((uint)1, false)]
[TestCase((uint)8, false)]
[TestCase((uint)15, false)]
[TestCase((uint)21, false)]
[TestCase((uint)22, false)]
[TestCase((uint)29, false)]
[TestCase((uint)34, false)]
[TestCase((uint)36, false)]
[TestCase((uint)43, false)]
[TestCase((uint)47, false)]
[TestCase((uint)50, false)]
[TestCase((uint)57, false)]
[TestCase((uint)60, false)]
[TestCase((uint)64, false)]
[TestCase((uint)71, false)]
[TestCase((uint)73, false)]
[TestCase((uint)78, false)]
[TestCase((uint)85, false)]
[TestCase((uint)86, false)]
[TestCase((uint)92, false)]
[TestCase((uint)99, false)]
[TestCase((uint)106, false)]
[TestCase((uint)112, false)]
[TestCase((uint)113, false)]
[TestCase((uint)120, false)]
[TestCase((uint)125, false)]
[TestCase((uint)127, false)]
[TestCase((uint)134, true)]
[TestCase((uint)138, true)]
[TestCase((uint)141, true)]
[TestCase((uint)148, true)]
[TestCase((uint)151, true)]
[TestCase((uint)155, true)]
[TestCase((uint)162, true)]
[TestCase((uint)164, true)]
[TestCase((uint)169, true)]
[TestCase((uint)176, true)]
[TestCase((uint)177, true)]
[TestCase((uint)183, true)]
[TestCase((uint)190, true)]
[TestCase((uint)197, true)]
[TestCase((uint)203, true)]
[TestCase((uint)204, true)]
[TestCase((uint)211, true)]
[TestCase((uint)216, true)]
[TestCase((uint)218, true)]
[TestCase((uint)225, true)]
[TestCase((uint)229, true)]
[TestCase((uint)232, true)]
[TestCase((uint)239, true)]
[TestCase((uint)242, true)]
[TestCase((uint)246, true)]
[TestCase((uint)253, true)]
[TestCase((uint)255, true)]
public void Bit7_Vooruit(uint b, bool expected)
{
// Act
bool actual = BAI_Afteken2.Vooruit(b);
// Assert
Assert.AreEqual(expected, actual);
}
}
}

77
Tests/Opdr2Tests.cs Normal file
View File

@ -0,0 +1,77 @@
using NUnit.Framework;
using System.Collections.Generic;
namespace BAI
{
[TestFixture]
public class Opdr2Tests
{
[TestCase("", "")]
[TestCase("1 8 18 21 34 35 47 52 60 69 73 86 99 103 112 120 125 137 138 151 154 164 171 177 188 190 203 205 216 222 229 239 242 255", "1 8 18 21 34 35 47 52 60 69 73 86 99 103 112 120 125 137 138 151 154 164 171 177 188 190 203 205 216 222 229 239 242 255")]
[TestCase("0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255", "0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255")]
public void Opdr2_1_Alle(string input, string expected)
{
// Prepare
List<uint> input_array = TestUtils.UIntListFromString(input);
// Act
HashSet<uint> actual_set = BAI_Afteken2.Alle(input_array);
string actual = TestUtils.EnumSortedToString(actual_set);
// Assert
Assert.AreEqual(expected, actual);
}
[TestCase("", "")]
[TestCase("1 8 18 21 34 35 47 52 60 69 73 86 99 103 112 120 125 137 138 151 154 164 171 177 188 190 203 205 216 222 229 239 242 255", "1 18 21 34 35 52 69 86 99 103 112 151 164 177 229 242")]
[TestCase("0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255", "0 1 2 3 4 5 6 7 16 17 18 19 20 21 22 23 32 33 34 35 36 37 38 39 48 49 50 51 52 53 54 55 64 65 66 67 68 69 70 71 80 81 82 83 84 85 86 87 96 97 98 99 100 101 102 103 112 113 114 115 116 117 118 119 128 129 130 131 132 133 134 135 144 145 146 147 148 149 150 151 160 161 162 163 164 165 166 167 176 177 178 179 180 181 182 183 192 193 194 195 196 197 198 199 208 209 210 211 212 213 214 215 224 225 226 227 228 229 230 231 240 241 242 243 244 245 246 247")]
public void Opdr2_2_ZonderLicht(string input, string expected)
{
// Prepare
List<uint> input_array = TestUtils.UIntListFromString(input);
// Act
HashSet<uint> actual_set = BAI_Afteken2.ZonderLicht(input_array);
string actual = TestUtils.EnumSortedToString(actual_set);
// Assert
Assert.AreEqual(expected, actual);
}
[TestCase("", "")]
[TestCase("1 8 18 21 34 35 47 52 60 69 73 86 99 103 112 120 125 137 138 151 154 164 171 177 188 190 203 205 216 222 229 239 242 255", "18 21 52 60 86 112 120 125 151 154 177 188 190 216 222 242 255")]
[TestCase("0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255", "16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255")]
public void Opdr2_3_MetWagon(string input, string expected)
{
// Prepare
List<uint> input_array = TestUtils.UIntListFromString(input);
// Act
HashSet<uint> actual_set = BAI_Afteken2.MetWagon(input_array);
string actual = TestUtils.EnumSortedToString(actual_set);
// Assert
Assert.AreEqual(expected, actual);
}
[TestCase("", "")]
[TestCase("1 8 18 21 34 35 47 52 60 69 73 86 99 103 112 120 125 137 138 151 154 164 171 177 188 190 203 205 216 222 229 239 242 255", "1 8 18 34 73 112 120 137 138 154 177 216 242")]
[TestCase("0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255", "0 1 2 8 9 10 16 17 18 24 25 26 32 33 34 40 41 42 48 49 50 56 57 58 64 65 66 72 73 74 80 81 82 88 89 90 96 97 98 104 105 106 112 113 114 120 121 122 128 129 130 136 137 138 144 145 146 152 153 154 160 161 162 168 169 170 176 177 178 184 185 186 192 193 194 200 201 202 208 209 210 216 217 218 224 225 226 232 233 234 240 241 242 248 249 250")]
public void Opdr2_4_SelecteerID(string input, string expected)
{
// Prepare
List<uint> input_array = TestUtils.UIntListFromString(input);
// Act
HashSet<uint> actual_set = BAI_Afteken2.SelecteerID(input_array, 0, 2);
string actual = TestUtils.EnumSortedToString(actual_set);
// Assert
Assert.AreEqual(expected, actual);
}
}
}

43
Tests/Opdr3Tests.cs Normal file
View File

@ -0,0 +1,43 @@
using NUnit.Framework;
using System.Collections.Generic;
namespace BAI
{
[TestFixture]
public class Opdr3Tests
{
[TestCase("", "")]
[TestCase("1 8 18 21 34 35 47 52 60 69 73 86 99 103 112 120 125 137 138 151 154 164 171 177 188 190 203 205 216 222 229 239 242 255", "1 18 34 112 177 242")]
[TestCase("0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255", "0 1 2 16 17 18 32 33 34 48 49 50 64 65 66 80 81 82 96 97 98 112 113 114 128 129 130 144 145 146 160 161 162 176 177 178 192 193 194 208 209 210 224 225 226 240 241 242")]
public void Opdr3_a_IDLager3_ZonderLicht(string input, string expected)
{
// Prepare
List<uint> input_array = TestUtils.UIntListFromString(input);
// Act
HashSet<uint> actual_set = BAI_Afteken2.Opdr3a(input_array);
string actual = TestUtils.EnumSortedToString(actual_set);
// Assert
Assert.AreEqual(expected, actual);
}
[TestCase("", "")]
[TestCase("1 8 18 21 34 35 47 52 60 69 73 86 99 103 112 120 125 137 138 151 154 164 171 177 188 190 203 205 216 222 229 239 242 255", "8 21 35 47 52 60 69 73 86 99 103 120 125 137 138 151 154 164 171 188 190 203 205 216 222 229 239 255")]
[TestCase("0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255", "3 4 5 6 7 8 9 10 11 12 13 14 15 19 20 21 22 23 24 25 26 27 28 29 30 31 35 36 37 38 39 40 41 42 43 44 45 46 47 51 52 53 54 55 56 57 58 59 60 61 62 63 67 68 69 70 71 72 73 74 75 76 77 78 79 83 84 85 86 87 88 89 90 91 92 93 94 95 99 100 101 102 103 104 105 106 107 108 109 110 111 115 116 117 118 119 120 121 122 123 124 125 126 127 131 132 133 134 135 136 137 138 139 140 141 142 143 147 148 149 150 151 152 153 154 155 156 157 158 159 163 164 165 166 167 168 169 170 171 172 173 174 175 179 180 181 182 183 184 185 186 187 188 189 190 191 195 196 197 198 199 200 201 202 203 204 205 206 207 211 212 213 214 215 216 217 218 219 220 221 222 223 227 228 229 230 231 232 233 234 235 236 237 238 239 243 244 245 246 247 248 249 250 251 252 253 254 255")]
public void Opdr3_b_IDHoger2_MetLicht(string input, string expected)
{
// Prepare
List<uint> input_array = TestUtils.UIntListFromString(input);
// Act
HashSet<uint> actual_set = BAI_Afteken2.Opdr3b(input_array);
string actual = TestUtils.EnumSortedToString(actual_set);
// Assert
Assert.AreEqual(expected, actual);
}
}
}

58
Tests/TestUtils.cs Normal file
View File

@ -0,0 +1,58 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Linq;
namespace BAI
{
public class TestUtils
{
// ------------------------------------------------------------
// Maakt een lijst op basis van een string.
// Getallen zijn ints, gescheiden door spaties
// ------------------------------------------------------------
public static List<int> IntListFromString(string str)
{
List<int> list = new List<int>();
if (str.Length > 0)
list = str.Split(" ").Select(Int32.Parse).ToList();
return list;
}
// ------------------------------------------------------------
// Maakt een lijst op basis van een string.
// Getallen zijn uints, gescheiden door spaties
// ------------------------------------------------------------
public static List<uint> UIntListFromString(string str)
{
List<uint> list = new List<uint>();
if (str.Length > 0)
list = str.Split(" ").Select(uint.Parse).ToList();
return list;
}
// ------------------------------------------------------------
// Maakt een string van een Enumerable.
// De enumerable kan eventueel gesorteerd worden (handig voor
// sets).
// ------------------------------------------------------------
public static string EnumToString<T>(IEnumerable<T> lst, bool sort = false)
{
List<T> lst2 = new List<T>(lst);
if (sort)
lst2.Sort();
return String.Join(" ", lst2);
}
// ------------------------------------------------------------
// Maakt een string van een Enumerable.
// Lijst wordt gesorteerd (handig voor vergelijken van sets).
// ------------------------------------------------------------
public static string EnumSortedToString<T>(IEnumerable<T> lst)
{
return EnumToString(lst, true);
}
}
}

19
Tests/Tests.csproj Normal file
View File

@ -0,0 +1,19 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<RootNamespace>BAI</RootNamespace>
<IsPackable>false</IsPackable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="NUnit" Version="3.12.0" />
<PackageReference Include="NUnit3TestAdapter" Version="3.16.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.5.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\BAI2\BAI2.csproj" />
</ItemGroup>
</Project>