Created
June 2, 2021 13:14
-
-
Save katipogluMustafa/bef7b90330147096dca99d6f0cb31030 to your computer and use it in GitHub Desktop.
Mocking in c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <time.h> | |
#include <stdlib.h> | |
#include <stdio.h> | |
#include <assert.h> | |
// gcc mocking.c -Wl,--wrap=rand -o mocking.exe | |
int __wrap_rand() | |
{ | |
return 5; | |
} | |
int get_random_dice() | |
{ | |
return (rand() % 6) + 1; | |
} | |
int enhance() | |
{ | |
int item_enhancement = 1; | |
int dice = get_random_dice(); | |
if(dice > 3) | |
item_enhancement = dice / 2; | |
return item_enhancement; | |
} | |
void test_enhance() | |
{ | |
assert(enhance() == 3); | |
} | |
int main() | |
{ | |
srand(time(NULL)); | |
test_enhance(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment