Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AI TestGen LLM #4

Merged
merged 15 commits into from
Jul 20, 2024
Merged

AI TestGen LLM #4

merged 15 commits into from
Jul 20, 2024

Conversation

iWas-Coder
Copy link
Member

@iWas-Coder iWas-Coder commented Jul 18, 2024

@iWas-Coder iWas-Coder added the ✨ feature New feature or request label Jul 18, 2024
@iWas-Coder iWas-Coder self-assigned this Jul 18, 2024
@iWas-Coder
Copy link
Member Author

This is an example of the output generated, pre-processed and then diff'ed against the original code:

--- ../../sparky/test/src/sk_hashmap_test.c	2024-06-12 21:23:57.397377883 +0200
+++ tmp.cc	2024-07-20 21:21:17.035844090 +0200
@@ -1,45 +1,35 @@
-/*
- * GNU Sparky --- A 5v5 character-based libre tactical shooter
- * Copyright (C) 2024 Wasym A. Alonso
- *
- * This file is part of Sparky.
- *
- * Sparky is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * Sparky is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with Sparky.  If not, see <http://www.gnu.org/licenses/>.
- */
-
-
 #include <carbon.h>
 #include <sk_hashmap.h>
 #include <sk_hashmap_test.h>
 
-static u8 sk_hashmap_test_create_destroy(void) {
+static u8 sk_hashmap_test_set_get_element_invalid_input(void) {
   sk_hashmap x = sk_hashmap_create(2 << 1, sizeof(int));
-  carbon_should_be(2 << 1, x.capacity);
-  carbon_should_be(sizeof(int), x.element_size);
-  carbon_should_be_true(x.data);
+  int i = 7, j;
+  carbon_should_be_false(sk_hashmap_set(&x, NULL, &i));
+  carbon_should_be_false(sk_hashmap_set(&x, "seven", NULL));
+  carbon_should_be_false(sk_hashmap_get(&x, NULL, &j));
+  carbon_should_be_false(sk_hashmap_get(&x, "seven", NULL));
   sk_hashmap_destroy(&x);
-  carbon_should_be(0, x.capacity);
-  carbon_should_be(0, x.element_size);
-  carbon_should_be_p(0, x.data);
   return 1;
 }
 
-static u8 sk_hashmap_test_set_get_element(void) {
+static u8 sk_hashmap_test_set_get_element_collision(void) {
   sk_hashmap x = sk_hashmap_create(2 << 1, sizeof(int));
   int i = 7, j;
   carbon_should_be_true(sk_hashmap_set(&x, "seven", &i));
-  carbon_should_be_true(sk_hashmap_get(&x, "seven", &j));
+  carbon_should_be_true(sk_hashmap_set(&x, "seventeen", &j));
+  carbon_should_be(j, *((int *) x.data + hash("seventeen", x.capacity)));
+  sk_hashmap_destroy(&x);
+  return 1;
+}
+
+static u8 sk_hashmap_test_set_get_element_large_data(void) {
+  sk_hashmap x = sk_hashmap_create(2 << 1, sizeof(int));
+  int i = 7, j;
+  char large_data[1024];
+  memset(large_data, 'a', sizeof(large_data));
+  carbon_should_be_true(sk_hashmap_set(&x, large_data, &i));
+  carbon_should_be_true(sk_hashmap_get(&x, large_data, &j));
   carbon_should_be(i, j);
   sk_hashmap_destroy(&x);
   return 1;
@@ -48,4 +38,7 @@
 void sk_hashmap_test_register(void) {
   CARBON_REGISTER_TEST(sk_hashmap_test_create_destroy);
   CARBON_REGISTER_TEST(sk_hashmap_test_set_get_element);
+  CARBON_REGISTER_TEST(sk_hashmap_test_set_get_element_invalid_input);
+  CARBON_REGISTER_TEST(sk_hashmap_test_set_get_element_collision);
+  CARBON_REGISTER_TEST(sk_hashmap_test_set_get_element_large_data);
 }

As can be seen, it generated 3 new tests, but didn't leave the original code intact (it nuked 'em all 😆).

Will continue working on it, but it's quite stable for now, so all its dev will be in the master branch, like all other features/fixes.

@iWas-Coder iWas-Coder marked this pull request as ready for review July 20, 2024 19:27
@iWas-Coder iWas-Coder merged commit 673f578 into master Jul 20, 2024
@iWas-Coder iWas-Coder deleted the feature/testgen branch July 20, 2024 19:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
✨ feature New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant