push for windows
This commit is contained in:
@@ -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 removeAnimal(int animalId, Animal* animalArray, size_t numberOfAnimalsPresent, size_t* newNumberOfAnimalsPresent){
|
||||||
int fault = 0;
|
|
||||||
size_t removedCount = 0;
|
size_t removedCount = 0;
|
||||||
|
|
||||||
if (animalArray == NULL || numberOfAnimalsPresent == 0) {
|
if (animalArray == NULL || numberOfAnimalsPresent == 0) {
|
||||||
@@ -35,26 +34,18 @@ int removeAnimal(int animalId, Animal* animalArray, size_t numberOfAnimalsPresen
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fault = removedCount;
|
|
||||||
*newNumberOfAnimalsPresent = (numberOfAnimalsPresent - removedCount);
|
*newNumberOfAnimalsPresent = (numberOfAnimalsPresent - removedCount);
|
||||||
return fault;
|
return removedCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
int findAnimalById(int animalId, const Animal* animalArray, size_t numberOfAnimalsPresent, Animal* foundAnimal) {
|
int findAnimalById(int animalId, const Animal* animalArray, size_t numberOfAnimalsPresent, Animal* foundAnimal) {
|
||||||
int fault = -1;
|
if (animalArray == NULL || foundAnimal == NULL) return -1; // Invalid input
|
||||||
if (animalArray == NULL || numberOfAnimalsPresent == 0 || foundAnimal == NULL) {
|
|
||||||
fault = -1;
|
for (size_t i = 0; i < numberOfAnimalsPresent; i++) {
|
||||||
} else {
|
if (animalArray[i].Id == animalId) {
|
||||||
for (size_t i = 0; i < numberOfAnimalsPresent; i++) {
|
*foundAnimal = animalArray[i];
|
||||||
if (animalArray[i].Id == animalId) {
|
return 0;
|
||||||
*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));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return fault;
|
return 0;
|
||||||
}
|
}
|
||||||
Binary file not shown.
@@ -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){
|
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
|
*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){
|
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_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
|
*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){
|
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
|
*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){
|
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){
|
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
|
*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){
|
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_high = (*date_bits_high & 0xF8) | ((month >> 1) & 0x07);
|
||||||
*date_bits_low = (*date_bits_low & 0x7F) | ((month & 0x01) << 7);
|
*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){
|
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
|
*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){
|
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){
|
||||||
|
|||||||
@@ -59,6 +59,25 @@ void test_setting_get_config_settings(void){
|
|||||||
watch_registers_get_config_settings(config, &is_paused, &format, &interval);
|
watch_registers_get_config_settings(config, &is_paused, &format, &interval);
|
||||||
TEST_ASSERT_EQUAL(TIME_EVERY_1_SECOND, 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
|
//time
|
||||||
void test_time_set_hours(void){
|
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_format);
|
||||||
MY_RUN_TEST(test_setting_set_config_time_update_interval);
|
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_settings);
|
||||||
|
MY_RUN_TEST(test_setting_get_config_settings2);
|
||||||
|
|
||||||
MY_RUN_TEST(test_time_set_hours);
|
MY_RUN_TEST(test_time_set_hours);
|
||||||
MY_RUN_TEST(test_time_set_minutes);
|
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_date_get_date);
|
||||||
|
|
||||||
MY_RUN_TEST(test_full_watch_configuration);
|
MY_RUN_TEST(test_full_watch_configuration);
|
||||||
MY_RUN_TEST(test_full_datetime_overflow_setup);
|
|
||||||
|
|
||||||
UnityUnregisterSetupTearDown();
|
UnityUnregisterSetupTearDown();
|
||||||
}
|
}
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
BIN
C/C6 Adidas.zip
Normal file
BIN
C/C6 Adidas.zip
Normal file
Binary file not shown.
BIN
CS/CS2B shipping company.zip
Normal file
BIN
CS/CS2B shipping company.zip
Normal file
Binary file not shown.
@@ -15,25 +15,25 @@ public class Company
|
|||||||
|
|
||||||
public string GenerateReport()
|
public string GenerateReport()
|
||||||
{
|
{
|
||||||
var report = new StringBuilder();
|
StringBuilder report = new StringBuilder();
|
||||||
report.AppendLine("| Id | Weight | Volume | Refrid | Fee |");
|
report.AppendLine("| Id | Weight | Volume | Refrid | Fee |");
|
||||||
|
|
||||||
// Process Full Containers
|
// Process FullContainers
|
||||||
var fullContainers = containers.OfType<FullContainer>().ToList();
|
List<FullContainer> fullContainers = containers.OfType<FullContainer>().ToList();
|
||||||
if (fullContainers.Any())
|
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($"| Full Size {container.Id} | {container.Weight}kg | | {(container.IsRefrigerated ? "Y" : "N")} | €{container.Fee():F2} |");
|
||||||
}
|
}
|
||||||
report.AppendLine($"| Total | | | €{fullContainers.Sum(c => c.Fee()):F2} |");
|
report.AppendLine($"| Total | | | €{fullContainers.Sum(c => c.Fee()):F2} |");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Process Half Containers
|
// Process HalfContainers
|
||||||
var halfContainers = containers.OfType<HalfContainer>().ToList();
|
List<HalfContainer> halfContainers = containers.OfType<HalfContainer>().ToList();
|
||||||
if (halfContainers.Any())
|
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} |");
|
report.AppendLine($"| Half Size {container.Id} | | {container.Volume}m3 | N/A | €{container.Fee():F2} |");
|
||||||
}
|
}
|
||||||
@@ -41,10 +41,10 @@ public class Company
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Process Quarter Containers
|
// Process Quarter Containers
|
||||||
var quarterContainers = containers.OfType<QuarterContainer>().ToList();
|
List<QuarterContainer> quarterContainers = containers.OfType<QuarterContainer>().ToList();
|
||||||
if (quarterContainers.Any())
|
if (quarterContainers.Any())
|
||||||
{
|
{
|
||||||
foreach (var container in quarterContainers)
|
foreach (QuarterContainer container in quarterContainers)
|
||||||
{
|
{
|
||||||
report.AppendLine($"| Quarter Size {container.Id} | | | N/A | €{container.Fee():F2} |");
|
report.AppendLine($"| Quarter Size {container.Id} | | | N/A | €{container.Fee():F2} |");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,13 +2,13 @@
|
|||||||
|
|
||||||
public class Program {
|
public class Program {
|
||||||
public static async Task Main(string[] args){
|
public static async Task Main(string[] args){
|
||||||
var company = new Company();
|
Company company = new Company();
|
||||||
var server = new Server(company);
|
Server server = new Server(company);
|
||||||
|
|
||||||
server.SetupServer();
|
server.SetupServer();
|
||||||
Console.WriteLine("Server started. Press any key to stop...");
|
Console.WriteLine("Server started. Press any key to stop...");
|
||||||
|
|
||||||
var serverTask = server.ServerLoop();
|
Task serverTask = server.ServerLoop();
|
||||||
|
|
||||||
Console.ReadKey();
|
Console.ReadKey();
|
||||||
server.StopServer();
|
server.StopServer();
|
||||||
|
|||||||
@@ -29,10 +29,10 @@ public class Server
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
using (var client = await listener.AcceptTcpClientAsync())
|
TcpClient client = await listener.AcceptTcpClientAsync();
|
||||||
using (var stream = client.GetStream())
|
NetworkStream stream = client.GetStream();
|
||||||
using (var reader = new StreamReader(stream))
|
StreamReader reader = new StreamReader(stream);
|
||||||
using (var writer = new StreamWriter(stream) { AutoFlush = true })
|
StreamWriter writer = new StreamWriter(stream) { AutoFlush = true };
|
||||||
{
|
{
|
||||||
await HandleClient(reader, writer);
|
await HandleClient(reader, writer);
|
||||||
}
|
}
|
||||||
@@ -50,7 +50,7 @@ public class Server
|
|||||||
{
|
{
|
||||||
await writer.WriteLineAsync("WELCOME");
|
await writer.WriteLineAsync("WELCOME");
|
||||||
|
|
||||||
var command = await reader.ReadLineAsync();
|
string? command = await reader.ReadLineAsync();
|
||||||
if (command == "STOP")
|
if (command == "STOP")
|
||||||
{
|
{
|
||||||
await writer.WriteLineAsync("ACK");
|
await writer.WriteLineAsync("ACK");
|
||||||
@@ -64,7 +64,7 @@ public class Server
|
|||||||
}
|
}
|
||||||
|
|
||||||
await writer.WriteLineAsync("TYPE");
|
await writer.WriteLineAsync("TYPE");
|
||||||
var type = await reader.ReadLineAsync();
|
string? type = await reader.ReadLineAsync();
|
||||||
|
|
||||||
BaseContainer container = null;
|
BaseContainer container = null;
|
||||||
|
|
||||||
@@ -104,14 +104,14 @@ public class Server
|
|||||||
private async Task<FullContainer> ProcessFullContainer(StreamReader reader, StreamWriter writer)
|
private async Task<FullContainer> ProcessFullContainer(StreamReader reader, StreamWriter writer)
|
||||||
{
|
{
|
||||||
await writer.WriteLineAsync("FRIDGE");
|
await writer.WriteLineAsync("FRIDGE");
|
||||||
var fridgeResponse = await reader.ReadLineAsync();
|
string? fridgeResponse = await reader.ReadLineAsync();
|
||||||
var isRefrigerated = fridgeResponse?.ToUpper() == "YES";
|
bool isRefrigerated = fridgeResponse?.ToUpper() == "YES";
|
||||||
|
|
||||||
await writer.WriteLineAsync("WEIGHT");
|
await writer.WriteLineAsync("WEIGHT");
|
||||||
if (!int.TryParse(await reader.ReadLineAsync(), out int weight))
|
if (!int.TryParse(await reader.ReadLineAsync(), out int weight))
|
||||||
throw new InvalidInputException("Invalid weight");
|
throw new InvalidInputException("Invalid weight");
|
||||||
|
|
||||||
var container = new FullContainer("Unknown", "Unknown")
|
FullContainer container = new FullContainer("Unknown", "Unknown")
|
||||||
{
|
{
|
||||||
IsRefrigerated = isRefrigerated,
|
IsRefrigerated = isRefrigerated,
|
||||||
Weight = weight
|
Weight = weight
|
||||||
@@ -126,7 +126,7 @@ public class Server
|
|||||||
if (!int.TryParse(await reader.ReadLineAsync(), out int volume))
|
if (!int.TryParse(await reader.ReadLineAsync(), out int volume))
|
||||||
throw new InvalidInputException("Invalid volume");
|
throw new InvalidInputException("Invalid volume");
|
||||||
|
|
||||||
var container = new HalfContainer("Unknown", "Unknown")
|
HalfContainer container = new HalfContainer("Unknown", "Unknown")
|
||||||
{
|
{
|
||||||
Volume = volume
|
Volume = volume
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ using System.Reflection;
|
|||||||
[assembly: System.Reflection.AssemblyCompanyAttribute("CS2B shipping company")]
|
[assembly: System.Reflection.AssemblyCompanyAttribute("CS2B shipping company")]
|
||||||
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
|
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
|
||||||
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
|
[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.AssemblyProductAttribute("CS2B shipping company")]
|
||||||
[assembly: System.Reflection.AssemblyTitleAttribute("CS2B shipping company")]
|
[assembly: System.Reflection.AssemblyTitleAttribute("CS2B shipping company")]
|
||||||
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
|
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
|
||||||
|
|||||||
@@ -1 +1 @@
|
|||||||
0913bbc8f927833caed9093ecdea2f944561fbcc44cfadc86e7b4634e0bfb243
|
f4ce571968b5b266f724fd1c97923543f743c6a4b13182626c331000da0b437e
|
||||||
|
|||||||
@@ -1 +1 @@
|
|||||||
17494093033930601
|
17495474612743232
|
||||||
Binary file not shown.
Reference in New Issue
Block a user