COMPUTER SCIENCE STRINGS ASSIGNMENT

profilekritha
templates.zip

PA203/main.c

// TODO - nothing, do not modify this file #include <stdio.h> #include <stdlib.h> extern void runAllTests(); int main() { printf("Welcome to the Tiny Taurahe Translator!!!\n\n\n"); runAllTests(); return EXIT_SUCCESS; }

PA203/PA203.cbp

PA203/PA203.depend

# depslib dependency file v1.0
1346967010 source:x:\3515 - it program design - oa - v5\w11 - 203 - pa203\students files\pa203\tests.c
<stdio.h>
<stdlib.h>
<string.h>
tools.h
1346967026 x:\3515 - it program design - oa - v5\w11 - 203 - pa203\students files\pa203\tools.h
1346966954 source:x:\3515 - it program design - oa - v5\w11 - 203 - pa203\students files\pa203\tools.c
<stdlib.h>
<stdio.h>
<string.h>
tools.h
1408406182 source:c:\users\alessiolpt\desktop\workbench\203\templates\pa203\main.c
<stdio.h>
<stdlib.h>
1408406802 source:c:\users\alessiolpt\desktop\workbench\203\templates\pa203\testlib.c
<stdlib.h>
<stdio.h>
testlib.h
1408406793 c:\users\alessiolpt\desktop\workbench\203\templates\pa203\testlib.h
1408406230 source:c:\users\alessiolpt\desktop\workbench\203\templates\pa203\tools.c
<stdlib.h>
<stdio.h>
<string.h>
tools.h
1408406022 c:\users\alessiolpt\desktop\workbench\203\templates\pa203\tools.h
1408406970 source:c:\users\alessiolpt\desktop\workbench\203\templates\pa203\tests.c
<stdio.h>
<stdlib.h>
<string.h>
tools.h
testlib.h

PA203/PA203.layout

PA203/testlib.c

// TODO - nothing, do not modify this file #include <stdlib.h> #include <stdio.h> #include "testlib.h" void TEST(const char * const shortDescription, int boolexp){ // keep track of tests numbers static int testNumber = 0; testNumber++; // string representing the outcome of the test char* testResult = NULL; // determining the outcome if(boolexp){ testResult = "OK"; }else{ testResult = "FAILS"; } printf("[Test] #%3d --> %-5.5s\t%-50.50s\n", testNumber, testResult, shortDescription); fflush(stdout); }

PA203/testlib.h

// TODO - nothing, do not modify this file #ifndef TESTLIB_H_INCLUDED #define TESTLIB_H_INCLUDED void TEST(const char * const shortDescription, int boolexp); /* ROLE This function display information about the test being "OK" or "FAILED" based on whether the condition used as parameter is respectively true or false PARAMETERS shortDescription a string describing the test. 45 characters long maximum boolexp the result of evaluating a boolean expression representing what we are testing. If it evaluates to true, the function will display that the test succeeded. Otherwise, it will display that the test failed. */ #endif // TESTLIB_H_INCLUDED

PA203/tests.c

// TODO - Implement your tests in this file using testlib functions #include <stdio.h> #include <stdlib.h> #include <string.h> #include "tools.h" #include "testlib.h" void test_single_word(){ // Example of test function char *translation = NULL; translation = taurahize_word("qwer"); TEST("Testing 4 letter word", strcmp(translation, "Aoke") == 0); free(translation); } void test_multiple_words(){ // Example of test function char *translation = NULL; translation = taurahize_word("qwer asdf tyui"); TEST("Testing 3 words", strcmp(translation, "Aoke Aoke Aoke") == 0); free(translation); } void runAllTests(){ // this is how you would use the tests examples above; // test_single_word(); // test_multiple_words(); }

PA203/tools.c

// TODO - Implement the functions in this file #include <stdlib.h> #include <stdio.h> #include <string.h> #include "tools.h" char *strdup (const char *s) { char *d = (char *)(malloc (strlen (s) + 1)); /* Space for length plus nul */ if (d == NULL) return NULL; /* No memory */ strcpy (d,s); /* Copy the characters */ return d; /* Return the new string */ } char* taurahize_word(const char * const word){ return strdup(word); // Useless right now, modify it } char* taurahize_phrase(const char* const phrase){ return strdup(phrase); // Useless right now, modify it }

PA203/tools.h

// TODO - nothing, do not modify this file #ifndef _TOOLS_H_ #define _TOOLS_H // Prototypes of functions char* taurahize_word(const char * const word); char* taurahize_phrase(const char* const phrase); #endif