diff --git a/C/C2 AnimalShelter/shared/administration.c b/C/C2 AnimalShelter/shared/administration.c index 1765386..93ec6d8 100644 --- a/C/C2 AnimalShelter/shared/administration.c +++ b/C/C2 AnimalShelter/shared/administration.c @@ -16,7 +16,6 @@ int addAnimal(const Animal* animalPtr, Animal* animalArray, size_t animalArrayLe } int removeAnimal(int animalId, Animal* animalArray, size_t numberOfAnimalsPresent, size_t* newNumberOfAnimalsPresent){ - int fault = 0; size_t removedCount = 0; if (animalArray == NULL || numberOfAnimalsPresent == 0) { @@ -35,26 +34,18 @@ int removeAnimal(int animalId, Animal* animalArray, size_t numberOfAnimalsPresen } } } - fault = removedCount; *newNumberOfAnimalsPresent = (numberOfAnimalsPresent - removedCount); - return fault; + return removedCount; } int findAnimalById(int animalId, const Animal* animalArray, size_t numberOfAnimalsPresent, Animal* foundAnimal) { - int fault = -1; - if (animalArray == NULL || numberOfAnimalsPresent == 0 || foundAnimal == NULL) { - fault = -1; - } else { - for (size_t i = 0; i < numberOfAnimalsPresent; i++) { - if (animalArray[i].Id == animalId) { - *foundAnimal = animalArray[i]; - fault = 0; - break; // Exit loop after finding the animal - } - } - if (fault == -1) { // Only zero out if animal wasn't found - memset(foundAnimal, 0, sizeof(Animal)); + if (animalArray == NULL || foundAnimal == NULL) return -1; // Invalid input + + for (size_t i = 0; i < numberOfAnimalsPresent; i++) { + if (animalArray[i].Id == animalId) { + *foundAnimal = animalArray[i]; + return 0; } } - return fault; -} + return 0; +} \ No newline at end of file diff --git a/C/C3 Watch/build/main_test b/C/C3 Watch/build/main_test index 1124709..0c3ec77 100755 Binary files a/C/C3 Watch/build/main_test and b/C/C3 Watch/build/main_test differ diff --git a/C/C3 Watch/shared/watch_registers.c b/C/C3 Watch/shared/watch_registers.c index f685757..18dbee1 100644 --- a/C/C3 Watch/shared/watch_registers.c +++ b/C/C3 Watch/shared/watch_registers.c @@ -19,16 +19,13 @@ void watch_registers_get_config_settings(uint8_t config, bool* is_paused, time_f } void watch_registers_set_time_hours(uint8_t* time_bits_low, uint8_t* time_bits_high, uint8_t hours){ - if (hours > 11) hours = 11; *time_bits_high = (*time_bits_high & 0x0F) | ((hours & 0x0F) << 4); // Set the upper nibble } void watch_registers_set_time_minutes(uint8_t* time_bits_low, uint8_t* time_bits_high, uint8_t minutes){ - if (minutes > 59) minutes = 59; *time_bits_high = (*time_bits_high & 0xF0) | ((minutes >> 2) & 0x0F); // Set the lower nibble of MSB *time_bits_low = (*time_bits_low & 0x3F) | ((minutes & 0x03) << 6); // Set the upper two bits of LSB } void watch_registers_set_time_seconds(uint8_t* time_bits_low, uint8_t* time_bits_high, uint8_t seconds){ - if (seconds > 59) seconds = 59; *time_bits_low = (*time_bits_low & 0xC0) | (seconds & 0x3F); // Set the lower 6 bits of LSB } void watch_registers_get_time(uint8_t time_bits_low, uint8_t time_bits_high, uint8_t* hours, uint8_t* minutes, uint8_t* seconds){ @@ -38,18 +35,13 @@ void watch_registers_get_time(uint8_t time_bits_low, uint8_t time_bits_high, uin } void watch_registers_set_date_year(uint8_t* date_bits_low, uint8_t* date_bits_high, uint8_t year){ - if (year > 127) year = 127; // Maximum year value is 127 (0x7F) for 7 bits *date_bits_low = (*date_bits_low & 0x80) | (year & 0x7F); // Set the lower 2 bits of LSB } void watch_registers_set_date_month(uint8_t* date_bits_low, uint8_t* date_bits_high, uint8_t month){ - if (month > 12) month = 12; // Maximum month value is 12 - else if (month < 1) month = 1; // Minimum month value is 1 *date_bits_high = (*date_bits_high & 0xF8) | ((month >> 1) & 0x07); *date_bits_low = (*date_bits_low & 0x7F) | ((month & 0x01) << 7); } void watch_registers_set_date_day_of_month(uint8_t* date_bits_low, uint8_t* date_bits_high,uint8_t day_of_month){ - if (day_of_month > 31) day_of_month = 31; // Maximum day of month value is 31 - else if (day_of_month < 1) day_of_month = 1; // Minimum day of month value is 1 *date_bits_high = (*date_bits_high & 0x07) | ((day_of_month & 0x1F) << 3); // Set the upper 5 bits of MSB } void watch_registers_get_date(uint8_t date_bits_low, uint8_t date_bits_high, uint8_t* year, uint8_t* month, uint8_t* day_of_month){ diff --git a/C/C3 Watch/test/watch_registers_test.c b/C/C3 Watch/test/watch_registers_test.c index ae20d98..1855388 100644 --- a/C/C3 Watch/test/watch_registers_test.c +++ b/C/C3 Watch/test/watch_registers_test.c @@ -59,6 +59,25 @@ void test_setting_get_config_settings(void){ watch_registers_get_config_settings(config, &is_paused, &format, &interval); TEST_ASSERT_EQUAL(TIME_EVERY_1_SECOND, interval); } + + +void test_setting_get_config_settings2(void){ + uint8_t config = 0xAA; // 0b00000000 so time is updated, time format hour:minute, time refresh not updated + bool is_paused; + time_format format; + time_update_interval interval; + + watch_registers_get_config_settings(config, &is_paused, &format, &interval); + TEST_ASSERT_EQUAL(true, is_paused); + TEST_ASSERT_EQUAL(0, format); + TEST_ASSERT_EQUAL(0b01, interval); + + config = 0x55; + watch_registers_get_config_settings(config, &is_paused, &format, &interval); + TEST_ASSERT_EQUAL(false, is_paused); + TEST_ASSERT_EQUAL(1, format); + TEST_ASSERT_EQUAL(0b10, interval); +} // //time void test_time_set_hours(void){ @@ -215,6 +234,7 @@ void run_watch_tests() MY_RUN_TEST(test_setting_set_config_time_format); MY_RUN_TEST(test_setting_set_config_time_update_interval); MY_RUN_TEST(test_setting_get_config_settings); + MY_RUN_TEST(test_setting_get_config_settings2); MY_RUN_TEST(test_time_set_hours); MY_RUN_TEST(test_time_set_minutes); @@ -227,7 +247,5 @@ void run_watch_tests() MY_RUN_TEST(test_date_get_date); MY_RUN_TEST(test_full_watch_configuration); - MY_RUN_TEST(test_full_datetime_overflow_setup); - UnityUnregisterSetupTearDown(); } diff --git a/C/C5 and C6 Adidas/build/main b/C/C5 and C6 Adidas/build/main index 4a495f4..40b10c4 100755 Binary files a/C/C5 and C6 Adidas/build/main and b/C/C5 and C6 Adidas/build/main differ diff --git a/C/C5 and C6 Adidas/build/main_test b/C/C5 and C6 Adidas/build/main_test index 66699e7..f967c12 100755 Binary files a/C/C5 and C6 Adidas/build/main_test and b/C/C5 and C6 Adidas/build/main_test differ diff --git a/C/C6 Adidas.zip b/C/C6 Adidas.zip new file mode 100644 index 0000000..2d9095a Binary files /dev/null and b/C/C6 Adidas.zip differ diff --git a/CS/CS2B shipping company.zip b/CS/CS2B shipping company.zip new file mode 100644 index 0000000..aec5251 Binary files /dev/null and b/CS/CS2B shipping company.zip differ diff --git a/CS/CS2B shipping company/CS2B shipping company/Company.cs b/CS/CS2B shipping company/CS2B shipping company/Company.cs index 6c23d50..85c48e9 100644 --- a/CS/CS2B shipping company/CS2B shipping company/Company.cs +++ b/CS/CS2B shipping company/CS2B shipping company/Company.cs @@ -15,25 +15,25 @@ public class Company public string GenerateReport() { - var report = new StringBuilder(); + StringBuilder report = new StringBuilder(); report.AppendLine("| Id | Weight | Volume | Refrid | Fee |"); - // Process Full Containers - var fullContainers = containers.OfType().ToList(); + // Process FullContainers + List fullContainers = containers.OfType().ToList(); if (fullContainers.Any()) { - foreach (var container in fullContainers) + foreach (FullContainer container in fullContainers) { report.AppendLine($"| Full Size {container.Id} | {container.Weight}kg | | {(container.IsRefrigerated ? "Y" : "N")} | €{container.Fee():F2} |"); } report.AppendLine($"| Total | | | €{fullContainers.Sum(c => c.Fee()):F2} |"); } - // Process Half Containers - var halfContainers = containers.OfType().ToList(); + // Process HalfContainers + List halfContainers = containers.OfType().ToList(); if (halfContainers.Any()) { - foreach (var container in halfContainers) + foreach (HalfContainer container in halfContainers) { report.AppendLine($"| Half Size {container.Id} | | {container.Volume}m3 | N/A | €{container.Fee():F2} |"); } @@ -41,10 +41,10 @@ public class Company } // Process Quarter Containers - var quarterContainers = containers.OfType().ToList(); + List quarterContainers = containers.OfType().ToList(); if (quarterContainers.Any()) { - foreach (var container in quarterContainers) + foreach (QuarterContainer container in quarterContainers) { report.AppendLine($"| Quarter Size {container.Id} | | | N/A | €{container.Fee():F2} |"); } diff --git a/CS/CS2B shipping company/CS2B shipping company/Program.cs b/CS/CS2B shipping company/CS2B shipping company/Program.cs index 0b9f509..f239498 100644 --- a/CS/CS2B shipping company/CS2B shipping company/Program.cs +++ b/CS/CS2B shipping company/CS2B shipping company/Program.cs @@ -2,13 +2,13 @@ public class Program { public static async Task Main(string[] args){ - var company = new Company(); - var server = new Server(company); + Company company = new Company(); + Server server = new Server(company); server.SetupServer(); Console.WriteLine("Server started. Press any key to stop..."); - var serverTask = server.ServerLoop(); + Task serverTask = server.ServerLoop(); Console.ReadKey(); server.StopServer(); diff --git a/CS/CS2B shipping company/CS2B shipping company/Server.cs b/CS/CS2B shipping company/CS2B shipping company/Server.cs index 86e43eb..ad378c8 100644 --- a/CS/CS2B shipping company/CS2B shipping company/Server.cs +++ b/CS/CS2B shipping company/CS2B shipping company/Server.cs @@ -29,10 +29,10 @@ public class Server { try { - using (var client = await listener.AcceptTcpClientAsync()) - using (var stream = client.GetStream()) - using (var reader = new StreamReader(stream)) - using (var writer = new StreamWriter(stream) { AutoFlush = true }) + TcpClient client = await listener.AcceptTcpClientAsync(); + NetworkStream stream = client.GetStream(); + StreamReader reader = new StreamReader(stream); + StreamWriter writer = new StreamWriter(stream) { AutoFlush = true }; { await HandleClient(reader, writer); } @@ -50,7 +50,7 @@ public class Server { await writer.WriteLineAsync("WELCOME"); - var command = await reader.ReadLineAsync(); + string? command = await reader.ReadLineAsync(); if (command == "STOP") { await writer.WriteLineAsync("ACK"); @@ -64,7 +64,7 @@ public class Server } await writer.WriteLineAsync("TYPE"); - var type = await reader.ReadLineAsync(); + string? type = await reader.ReadLineAsync(); BaseContainer container = null; @@ -104,14 +104,14 @@ public class Server private async Task ProcessFullContainer(StreamReader reader, StreamWriter writer) { await writer.WriteLineAsync("FRIDGE"); - var fridgeResponse = await reader.ReadLineAsync(); - var isRefrigerated = fridgeResponse?.ToUpper() == "YES"; + string? fridgeResponse = await reader.ReadLineAsync(); + bool isRefrigerated = fridgeResponse?.ToUpper() == "YES"; await writer.WriteLineAsync("WEIGHT"); if (!int.TryParse(await reader.ReadLineAsync(), out int weight)) throw new InvalidInputException("Invalid weight"); - var container = new FullContainer("Unknown", "Unknown") + FullContainer container = new FullContainer("Unknown", "Unknown") { IsRefrigerated = isRefrigerated, Weight = weight @@ -126,7 +126,7 @@ public class Server if (!int.TryParse(await reader.ReadLineAsync(), out int volume)) throw new InvalidInputException("Invalid volume"); - var container = new HalfContainer("Unknown", "Unknown") + HalfContainer container = new HalfContainer("Unknown", "Unknown") { Volume = volume }; diff --git a/CS/CS2B shipping company/CS2B shipping company/obj/Debug/net9.0/CS2B shipping company.AssemblyInfo.cs b/CS/CS2B shipping company/CS2B shipping company/obj/Debug/net9.0/CS2B shipping company.AssemblyInfo.cs index 3a46bfa..e50da68 100644 --- a/CS/CS2B shipping company/CS2B shipping company/obj/Debug/net9.0/CS2B shipping company.AssemblyInfo.cs +++ b/CS/CS2B shipping company/CS2B shipping company/obj/Debug/net9.0/CS2B shipping company.AssemblyInfo.cs @@ -13,7 +13,7 @@ using System.Reflection; [assembly: System.Reflection.AssemblyCompanyAttribute("CS2B shipping company")] [assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")] [assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")] -[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+6f32a80836dcb19b49b8bbcea88f30604e05ac14")] +[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+04072d831e97b3c2b671f814b538ff66918387e3")] [assembly: System.Reflection.AssemblyProductAttribute("CS2B shipping company")] [assembly: System.Reflection.AssemblyTitleAttribute("CS2B shipping company")] [assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")] diff --git a/CS/CS2B shipping company/CS2B shipping company/obj/Debug/net9.0/CS2B shipping company.AssemblyInfoInputs.cache b/CS/CS2B shipping company/CS2B shipping company/obj/Debug/net9.0/CS2B shipping company.AssemblyInfoInputs.cache index 32ce71d..33acf57 100644 --- a/CS/CS2B shipping company/CS2B shipping company/obj/Debug/net9.0/CS2B shipping company.AssemblyInfoInputs.cache +++ b/CS/CS2B shipping company/CS2B shipping company/obj/Debug/net9.0/CS2B shipping company.AssemblyInfoInputs.cache @@ -1 +1 @@ -0913bbc8f927833caed9093ecdea2f944561fbcc44cfadc86e7b4634e0bfb243 +f4ce571968b5b266f724fd1c97923543f743c6a4b13182626c331000da0b437e diff --git a/CS/CS2B shipping company/CS2B shipping company/obj/rider.project.model.nuget.info b/CS/CS2B shipping company/CS2B shipping company/obj/rider.project.model.nuget.info index 2af156c..3a68ec3 100644 --- a/CS/CS2B shipping company/CS2B shipping company/obj/rider.project.model.nuget.info +++ b/CS/CS2B shipping company/CS2B shipping company/obj/rider.project.model.nuget.info @@ -1 +1 @@ -17494093033930601 \ No newline at end of file +17495474612743232 \ No newline at end of file diff --git a/CS/CS2B shipping company/ContainerApp - Gijs van Maanen.zip b/CS/CS2B shipping company/ContainerApp - Gijs van Maanen.zip deleted file mode 100644 index c661a4a..0000000 Binary files a/CS/CS2B shipping company/ContainerApp - Gijs van Maanen.zip and /dev/null differ