Move History

Fork Selected
  • Code
    #include <stdlib.h>
    #include <string.h>
    
    char *disemvowel(char *string)
    {
      char *res = (char*)malloc(strlen(string)), *s = res;
      for (; *string != '\0'; string++) if (!strchr("aeiouAEIOU", *string)) *res++ = *string;
      *res = '\0';
      return s;
    }
    Test Cases
    #include <criterion/criterion.h>
    #include <stdlib.h>
    #include <string.h>
    
    char* disemvowel(char *string);
    
    void tester(char *input, const char *exp) 
    {
      char *result = disemvowel(input);
      cr_assert_str_eq(result, exp, "Expected '%s', but got '%s'.", exp, result);
      free(result);
    }
    
    Test(remove_string, removes_vowels_from_a_string) 
    {
      tester("hello", "hll");
      tester("world", "wrld");
      tester("apple", "ppl");
    }
    
    Test(remove_string, handles_uppercase_and_lowercase_vowels) 
    {
      tester("Hello World", "Hll Wrld");
      tester("aEiOu", "");
    }
    
    Test(remove_string, handles_strings_with_no_vowels) 
    {
      tester("nthng hr", "nthng hr");
      tester("bcdfghjklmnpqrstvwxyz", "bcdfghjklmnpqrstvwxyz");
    }
    
    Test(remove_string, handles_empty_string) 
    {
      tester("", "");
    }
    
    Test(remove_string, handles_strings_with_only_vowels) 
    {
      tester("aeiouAEIOU", "");
    }
    
    Test(remove_string, handles_strings_with_special_characters) 
    {
      tester("Shrek is an orge!", "Shrk s n rg!");
      tester("The quick brown fox jumps over the lazy dog.", "Th qck brwn fx jmps vr th lzy dg.");
    }
    
  • Code
    • def disemvowel(string_):
    • vowels = ["a", "e", "i", "o", "u"]
    • new_txt = ""
    • for i in range(len(string_)):
    • if string_[i].lower() in vowels:
    • continue
    • else:
    • new_txt += string_[i]
    • return new_txt
    • #include <stdlib.h>
    • #include <string.h>
    • char *disemvowel(char *string)
    • {
    • char *res = (char*)malloc(strlen(string)), *s = res;
    • for (; *string != '\0'; string++) if (!strchr("aeiouAEIOU", *string)) *res++ = *string;
    • *res = '\0';
    • return s;
    • }
    Test Cases
    • import codewars_test as test
    • # TODO Write tests
    • import solution # or from solution import example
    • # test.assert_equals(actual, expected, [optional] message)
    • @test.describe("Example")
    • def test_group():
    • @test.it("test case")
    • def hi_guys():
    • test.assert_equals(disemvowel("HI GUYS"), "H GYS")
    • test.assert_equals(disemvowel("AEIOU"), "")
    • test.assert_equals(disemvowel("Shrek is an orge"), "Shrk s n rg")
    • #include <criterion/criterion.h>
    • #include <stdlib.h>
    • #include <string.h>
    • char* disemvowel(char *string);
    • void tester(char *input, const char *exp)
    • {
    • char *result = disemvowel(input);
    • cr_assert_str_eq(result, exp, "Expected '%s', but got '%s'.", exp, result);
    • free(result);
    • }
    • Test(remove_string, removes_vowels_from_a_string)
    • {
    • tester("hello", "hll");
    • tester("world", "wrld");
    • tester("apple", "ppl");
    • }
    • Test(remove_string, handles_uppercase_and_lowercase_vowels)
    • {
    • tester("Hello World", "Hll Wrld");
    • tester("aEiOu", "");
    • }
    • Test(remove_string, handles_strings_with_no_vowels)
    • {
    • tester("nthng hr", "nthng hr");
    • tester("bcdfghjklmnpqrstvwxyz", "bcdfghjklmnpqrstvwxyz");
    • }
    • Test(remove_string, handles_empty_string)
    • {
    • tester("", "");
    • }
    • Test(remove_string, handles_strings_with_only_vowels)
    • {
    • tester("aeiouAEIOU", "");
    • }
    • Test(remove_string, handles_strings_with_special_characters)
    • {
    • tester("Shrek is an orge!", "Shrk s n rg!");
    • tester("The quick brown fox jumps over the lazy dog.", "Th qck brwn fx jmps vr th lzy dg.");
    • }