initial commit

This commit is contained in:
KaseToatz1337
2024-10-03 12:31:17 +02:00
commit 49a3e34610
9 changed files with 469 additions and 0 deletions

30
Tests/Opdr1Tests.cs Normal file
View File

@ -0,0 +1,30 @@
using NUnit.Framework;
using System.Collections.Generic;
using System.Linq;
namespace BAI
{
[TestFixture]
public class Opdr1Tests
{
[TestCase("", "")] // Lege lijst
[TestCase("1 3 5 7 3 8 9 5", "3 5 3 5")] // Voorbeeld
[TestCase("42", "")] // Slechts 1 item
[TestCase("1 2 3 4 1 2 4 3 6 9 7 8 6 8 7 9", "1 2 3 4 1 2 4 3 6 9 7 8 6 8 7 9")] // Allemaal repeterend
[TestCase("7 7 7 7 7", "7 7 7 7 7")] // Alleen maar repeterend
[TestCase("1 3 7 10 15 89 2 6", "")] // Niets repeterend
[TestCase("165 166 172 12 342 217 441 150 383 379 23 440 179 286 206 395 157 141 358 388 39 419 376 491 55 481 392 337 218 234 232 421 307 243 214 377 158 430 352 430 191 242 152 76 302 6 396 419 56 104 197 59 287 197 471 246 290 181 456 360 324 104 431 150 148 102 133 436 72 329 237 226 289 427 198 296 267 300 189 50 86 472 282 115 37 173 135 111 271 468 88 476 474 491 107 87 310 3 428 201 372 459 348 226 366 471 269 359 498 176 478 489 491 406 275 351 322 317 113 474 466 22 166 104 242 261 251 298 321 112 485 265 371 488 177 126 125 56 248 65 403 276 113 96 489 98 484 69 216 256 264 493 389 454 235 351 294 245 484 106 220 471 38 387 190 213 119 4 229 150 226 267 69 48 71 190 409 71 114 145 276 183 83 66 347 492 376 417 253 326 331 380 71 143 344 432 238 226 405 277 478 481 339 67 30 497 425 341 383 45 441 224 131 339 330 38 388 472 40 198 337 201 250 402 318 346 196 425 203 139 452 184 165 337 166 295 343 17 36 350 68 35 35 209 385 108 249 232 313 307 44 266 186 208 439 277 231 436 248 184 302 499 138 244 93 257 60 294 174 35 194 372 436 190 131 303 167 42 18 211 97 464 113 396 95 186 498 456 397 388 64 406 269 352 48 68 396 290 117 128",
"165 166 441 150 383 388 419 376 491 481 337 232 307 430 352 430 242 302 396 419 56 104 197 197 471 290 456 104 150 436 226 198 267 472 474 491 201 372 226 471 269 498 478 489 491 406 351 113 474 166 104 242 56 248 276 113 489 484 69 351 294 484 471 38 190 150 226 267 69 48 71 190 71 276 376 71 226 277 478 481 339 425 383 441 131 339 38 388 472 198 337 201 425 184 165 337 166 68 35 35 232 307 186 277 436 248 184 302 294 35 372 436 190 131 113 396 186 498 456 388 406 269 352 48 68 396 290")]
public void Opdr1(string input_str, string expected)
{
// Arrange
List<int> list = TestUtils.IntListFromString(input_str);
// Act
BAI_Afteken1.Opdr1FilterList(list);
// Assert
Assert.AreEqual(expected, TestUtils.EnumToString(list));
}
}
}

89
Tests/Opdr2Tests.cs Normal file
View File

@ -0,0 +1,89 @@
using NUnit.Framework;
using System;
using System.Collections.Generic;
using System.Linq;
namespace BAI
{
[TestFixture]
public class Opdr2Tests
{
[Test]
public void Opdr2a_Queue50_01_SizeOk()
{
// Arrange
int expected = 50;
// Act
Queue<int> queue = BAI_Afteken1.Opdr2aQueue50();
int actual = queue.Count;
// Assert
Assert.AreEqual(expected, actual);
}
[Test]
public void Opdr2a_Queue50_02_ContentsOk()
{
// Arrange
// Act
Queue<int> queue = BAI_Afteken1.Opdr2aQueue50();
// Assert
int expected = 1;
while (queue.Count > 0)
{
int actual = queue.Dequeue();
Assert.AreEqual(expected, actual);
expected++;
}
}
[TestCase("", "")] // Leeg
[TestCase("1 3 -11 123 737", "")] // Geen delers van 4
[TestCase("0 4 44 -20 120 4444", "4444 120 -20 44 4 0")] // Allemaal delers van 4
[TestCase("1 2 3 4 5 6 7 -8 9", "-8 4")]
[TestCase("174 7 180 387 353 378 111 435 170 333 31 328 144 65 169 195 134 442 341 408 254 442 122 325 375 314 104 96 225 10 380 267 376 226 286 466 185 81 167 308 388 448 370 200 217 7 470 435 226 345 396 272 106 162 280 232 385 355 13 39 274 15 211 161 453 263 452 418 279 202 10 54 276 33 20 306 72 421 108 369 344 169 370 379 113 108 162 214 445 54 82 330 69 128 35 374 237 210 247 454 55 52 156 24 335 343 496 74 143 473 161 463 247 144 195 105 144 331 48 345 102 238 472 225 121 180 484 148 498 146 70 362 175 154 314 292 14 347 44 269 112 89 72 471 393 119 84 425 433 429 231 406 162 401 353 317 80 430 403 156 358 348 75 497 404 298 288 94 329 402 92 296 287 278 234 13 167 2 332 2 96 60 215 69 414 163 201 273 300 497 213 83 444 388 411 263 14 75 67 95 330 489 96 31 338 434 119 383 168 340 150 78 99 401 60 298 134 7 83 241 98 16 293 332 189 9 352 399 367 470 499 93 434 237 172 107 464 184 230 480 45 317 105 459 347 136 484 43 328 113 130 8 491 325 497 314 196 264 342 329 82 220 16 198 341 58 143 361 229 453 334 449 276 102 197 280 411 334 484 54 25 309 72 254 341 491 101 110 240 358 410 201 342 400 398 325 301 407 119 290",
"400 240 72 484 280 276 16 220 264 196 8 328 484 136 480 184 464 172 352 332 16 60 340 168 96 388 444 300 60 96 332 296 92 288 404 348 156 80 84 72 112 44 292 148 484 180 472 48 144 144 496 24 156 52 128 108 344 108 72 20 276 452 232 280 272 396 200 448 388 308 376 380 96 104 408 144 328 180")]
public void Opdr2b_StackFromQueue_01_ContentsOk(string input_str, string expected)
{
// Arrange
Queue<int> queue = new Queue<int>();
List<int> list = TestUtils.IntListFromString(input_str);
foreach (int x in list)
{
queue.Enqueue(x);
}
// Act
Stack<int> stack = BAI_Afteken1.Opdr2bStackFromQueue(queue);
// Assert
Assert.AreEqual(expected, TestUtils.EnumToString(stack));
}
[TestCase("")]
[TestCase("1 3 -11 123 737")]
[TestCase("0 4 44 -20 120 4444")]
[TestCase("1 2 3 4 5 6 7 -8 9")]
[TestCase("174 7 180 387 353 378 111 435 170 333 31 328 144 65 169 195 134 442 341 408 254 442 122 325 375 314 104 96 225 10 380 267 376 226 286 466 185 81 167 308 388 448 370 200 217 7 470 435 226 345 396 272 106 162 280 232 385 355 13 39 274 15 211 161 453 263 452 418 279 202 10 54 276 33 20 306 72 421 108 369 344 169 370 379 113 108 162 214 445 54 82 330 69 128 35 374 237 210 247 454 55 52 156 24 335 343 496 74 143 473 161 463 247 144 195 105 144 331 48 345 102 238 472 225 121 180 484 148 498 146 70 362 175 154 314 292 14 347 44 269 112 89 72 471 393 119 84 425 433 429 231 406 162 401 353 317 80 430 403 156 358 348 75 497 404 298 288 94 329 402 92 296 287 278 234 13 167 2 332 2 96 60 215 69 414 163 201 273 300 497 213 83 444 388 411 263 14 75 67 95 330 489 96 31 338 434 119 383 168 340 150 78 99 401 60 298 134 7 83 241 98 16 293 332 189 9 352 399 367 470 499 93 434 237 172 107 464 184 230 480 45 317 105 459 347 136 484 43 328 113 130 8 491 325 497 314 196 264 342 329 82 220 16 198 341 58 143 361 229 453 334 449 276 102 197 280 411 334 484 54 25 309 72 254 341 491 101 110 240 358 410 201 342 400 398 325 301 407 119 290")]
public void Opdr2b_StackFromQueue_02_QueueBecomesEmpty(string input_str)
{
// Arrange
Queue<int> queue = new Queue<int>();
List<int> list = TestUtils.IntListFromString(input_str);
foreach (int x in list)
{
queue.Enqueue(x);
}
int expected = 0;
// Act
Stack<int> stack = BAI_Afteken1.Opdr2bStackFromQueue(queue);
int actual = queue.Count;
// Assert
Assert.AreEqual(expected, actual);
}
}
}

87
Tests/Opdr3Tests.cs Normal file
View File

@ -0,0 +1,87 @@
using Microsoft.VisualBasic;
using NUnit.Framework;
using System.Collections.Generic;
using System.Linq;
namespace BAI
{
[TestFixture]
public class Opdr3Tests
{
[TestCase(1, 100, 100)] // 100 getallen, keuze uit 100
[TestCase(100, 100, 1)] // 1 getal, keuze uit 1
[TestCase(1, 100, 4)] // 4 getallen, keuze uit 100
[TestCase(-10, 20, 30)] // negatieve lower
[TestCase(-50, -20, 10)] // negatieve upper en lower
[TestCase(0, 1_000_000, 10_000)] // Veel getallen
public void Opdr3_01_SizeOk(int lower, int upper, int count)
{
// Arrange
Stack<int> stack;
int expected = count;
// Act
stack = BAI_Afteken1.Opdr3RandomNumbers(lower, upper, count);
int actual = stack.Count;
// Assert
Assert.AreEqual(expected, actual);
}
[TestCase(1, 100, 100)] // 100 getallen, keuze uit 100
[TestCase(100, 100, 1)] // 1 getal, keuze uit 1
[TestCase(1, 100, 4)] // 4 getallen, keuze uit 100
[TestCase(-10, 20, 30)] // negatieve lower
[TestCase(-50, -20, 10)] // negatieve upper en lower
[TestCase(0, 1_000_000, 10_000)] // Veel getallen
public void Opdr3_02_UniqueNumbers(int lower, int upper, int count)
{
// Arrange
Stack<int> stack;
int expected = count;
// Act
stack = BAI_Afteken1.Opdr3RandomNumbers(lower, upper, count);
int actual = stack.Distinct().Count<int>();
// Assert
Assert.AreEqual(expected, actual);
}
[TestCase(1, 100, 100)] // 100 getallen, keuze uit 100
[TestCase(100, 100, 1)] // 1 getal, keuze uit 1
[TestCase(1, 100, 4)] // 4 getallen, keuze uit 100
[TestCase(-10, 20, 30)] // negatieve lower
[TestCase(-50, -20, 10)] // negatieve upper en lower
[TestCase(0, 1_000_000, 10_000)] // Veel getallen
public void Opdr3_03_BoundsOk(int lower, int upper, int count)
{
// Arrange
Stack<int> stack;
int expected = 0;
// Act
stack = BAI_Afteken1.Opdr3RandomNumbers(lower, upper, count);
var out_bounds = stack.Where<int>(num => num < lower || num > upper);
int actual = out_bounds.Count<int>();
// Assert
Assert.AreEqual(expected, actual);
}
//
// Als deze test faalt, dan is de complexiteit van de oplossing verkeerd. Door
// minder lusjes te gebruiken of betere datastructuren, kun je er voor zorgen
// dat de test wel binnen 5 seconden slaagt.
//
[Test, Timeout(5000)]
public void Opdr3_04_ComplexityOk()
{
// Act
Stack<int> stack = BAI_Afteken1.Opdr3RandomNumbers(100_000, 500_000, 400_001); // Veel getallen, elk getal komt 1x voor
}
}
}

45
Tests/TestUtils.cs Normal file
View File

@ -0,0 +1,45 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace BAI
{
public class TestUtils
{
// ------------------------------------------------------------
// Maakt een lijst van een string. Getallen zijn ints,
// gescheiden door een spatie
// ------------------------------------------------------------
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 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>
<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="..\BAI1\BAI1.csproj" />
</ItemGroup>
</Project>