Sha256: a117d5193dbe71a2cbf69e74d4b867f7a6fc4b7f6e334a857fd6aa01f760d878
Contents?: true
Size: 1.55 KB
Versions: 3
Compression:
Stored size: 1.55 KB
Contents
#include "../foundationallib.h" #include <assert.h> #include <stdio.h> // Function to be tested void print_ushort_to_stream(const unsigned short value, FILE *stream) { fprintf(stream, "%hu", value); } // Test cases void test_print_ushort_to_stream_positive_value() { FILE *stream = fopen("test_output.txt", "w"); unsigned short test_value = 123; print_ushort_to_stream(test_value, stream); fclose(stream); FILE *file = fopen("test_output.txt", "r"); unsigned short result_value; fscanf(file, "%hu", &result_value); fclose(file); assert(result_value == test_value); } void test_print_ushort_to_stream_zero_value() { FILE *stream = fopen("test_output.txt", "w"); unsigned short test_value = 0; print_ushort_to_stream(test_value, stream); fclose(stream); FILE *file = fopen("test_output.txt", "r"); unsigned short result_value; fscanf(file, "%hu", &result_value); fclose(file); assert(result_value == test_value); } void test_print_ushort_to_stream_max_value() { FILE *stream = fopen("test_output.txt", "w"); unsigned short test_value = USHRT_MAX; print_ushort_to_stream(test_value, stream); fclose(stream); FILE *file = fopen("test_output.txt", "r"); unsigned short result_value; fscanf(file, "%hu", &result_value); fclose(file); assert(result_value == test_value); } int main() { test_print_ushort_to_stream_positive_value(); test_print_ushort_to_stream_zero_value(); test_print_ushort_to_stream_max_value(); printf("All tests passed!\n"); return 0; }
Version data entries
3 entries across 3 versions & 2 rubygems