#include <string.h>
/* String manipulation lab
15 points total
*/

int main() {
   int score =0;
   int BUFLEN = 100;
   int result;
   char * testzero = "";
   char * testnine = "123456789";
   char * testten = "1234567890";
   char buf[BUFLEN];
   
   /* *** mystrlen *** 
   6 test cases, 6 points
   
   */
   printf ("%s", "mystrlen tests\n");
   if (mystrlen(testzero,1) == 0) score ++;
   else printf("failed zero length string test on line %d\n", __LINE__);

   if (mystrlen(testnine,10) == 9) score ++;
   else printf("failed length nine test on line %d\n", __LINE__);

   if (mystrlen(testten,11) == 10) score ++;
   else printf("failed length ten test on line %d\n", __LINE__);

   if (mystrlen(testnine, 9) == 8) score ++;
      /* this stems from the fact that in a buffer of size N, there 
         can be only N-1 characters
      */
   else printf("failed no termination test on line %d\n", __LINE__);

   if (mystrlen(testnine, 0) == 0) score ++;
   else printf("failed zero length buffer test on line %d\n", __LINE__);

   strncpy(buf, testten, BUFLEN -1);
   buf[BUFLEN] = '\0';
   if (mystrlen(buf, BUFLEN) == 10) score ++;
   else printf("failed large buffer test on line %d\n", __LINE__);

   if (6 == score) {
      printf("Congratulations, you have a perfect mystrlen score (%d)!\n", score);
   } else {
      printf("mystrlen score: %d/6\n", score);
   }
   
   /* *** mystrcpy *** */
   printf ("%s", "mystrcpy tests\n");
   score = 0;
   
   result = mystrcpy(buf, testzero, BUFLEN, 1);
   if (result == 0) {
      if (buf[0] == '\0') score ++;
      else printf("Empty string copy test incorrect copy on line %d\n", __LINE__);
   }  else {
      printf("Empty string copy test reported truncation on line %d\n", __LINE__);
   }
   
   buf[0] = -128;
   result = mystrcpy(buf, testzero, 0, 1);
   if (result == 1) {
      if (buf[0] == -128 ) score ++;
      else printf("failed: truncation in zero-length destination buffer string copy test incorrect copy on line %d\n", __LINE__);
   }  else {
      printf("failed: truncation in zero-length destination buffer in string copy test reported no truncation on line %d\n", __LINE__);
   }

   buf[0] = -128;
   result = mystrcpy(buf, testzero, BUFLEN, 0);
   if (result == 1) {
      if (buf[0] == '\0') score ++;
      else printf("failed truncation in string copy test on line %d\n", __LINE__);
   }  else {
      printf("failed truncation in string copy test reported truncation on line %d\n", __LINE__);
   }
   /* Note: Jared personally disagrees with the truncation test: 
   result = mystrcpy(buf, testzero, BUFLEN, 0); 
   if (result == 1) 
      You truncated the string 
   else 
      you failed // I think you succeeded. When src_len is 0, you won't ever 
                  // truncate the destination string 
   Pascal's answer:
   If you reach the source size limit, that means that the source is not null-terminated.  This is an error condition;  I think of it as "source truncation".  If you wished, you could return different error codes for destination truncation and source truncation.  But, in both cases, an error should be raised because something unexpected happened.
   */
   buf[0] = -128;
   result = mystrcpy(buf, testten, 10, 11);
   if (result == 1) {
      if (strcmp(buf, testnine) == 0 ) {
         score ++;
      } else {
         printf("failed: truncation in destination buffer string copy test incorrect copy on line %d\n", __LINE__);
      }
   }  else {
      printf("failed: truncation in destination buffer in string copy test reported no truncation on line %d\n", __LINE__);
   }

   
   result = mystrcpy(buf, testnine, BUFLEN, 10);
   if (result == 0) {
      if (strcmp(buf, testnine) == 0 ) {
         score ++;
      } else {
         printf("failed normal string copy test on line %d\n", __LINE__);
      }
   }
   
   
   if (5 == score) {
      printf("Congratulations, you have a perfect mystrcpy score (%d)!\n", score);
   } else {
      printf("total score: %d\n", score);
   }
   
   /* *** mystrcat *** */
   printf ("%s", "mystrcat tests\n");
   score = 0;
   
   buf[0] ='\0';
   result = mystrcat(buf, testnine, BUFLEN, 10);
   if (result == 0) {
      if (strcmp(buf, testnine) == 0 ) score ++;
      else printf("failed normal string concatenation test on line %d\n", __LINE__);
   }
   
   buf[0] ='\0';
   result = mystrcat(buf, testten, 10, 11);
   if (result == 1) {
      if (strcmp(buf, testnine) == 0 ) score ++;
      else printf("failed: truncation in destination buffer test; incorrect copy on line %d\n", __LINE__);
   }  else {
      printf("failed: truncation in destination buffer test; reported no truncation on line %d\n", __LINE__);
   }

   strncpy(buf, testten, BUFLEN -1);
   buf[BUFLEN] = '\0';
   result = mystrcat(buf, testten, BUFLEN, 11);
   if (result == 0) {
      if (strcmp(buf, "12345678901234567890") == 0 ) score ++;
      else printf("failed: append test; incorrect copy on line %d\n", __LINE__);
   }  else {
      printf("failed: append test %d\n", __LINE__);
   }
   

   strncpy(buf, testten, BUFLEN -1);
   buf[BUFLEN] = '\0';
   result = mystrcat(buf, testten, 20, 11);
   if (result == 1) {
      if (strcmp(buf, "1234567890123456789") == 0 ) score ++;
      else printf("failed: append with truncation test; incorrect copy on line %d\n", __LINE__);
   }  else {
      printf("failed: append with truncation test; reported no truncation on line %d\n", __LINE__);
   }
   
   
   if (4 == score) {
      // More tests are needed 
      printf("Congratulations, you have a perfect mystrcat score (%d)!\n", score);
   } else {
      printf("total score: %d\n", score);
   }
}   
---------------Only modify the lines below!------------------
int mystrlen(const char *s, size_t s_len) {
   return 0;
}

int mystrcpy(char * dst, const char * src,
   size_t dst_len, size_t src_len) {
   return 0;
}

int mystrcat(char * s, const char * append, 
   size_t s_len, size_t a_len) {
   return 0;
}

