From 4cbe431c02d30fb2f9d02e33ce43d6fcd4bd77c4 Mon Sep 17 00:00:00 2001 From: cchudant Date: Fri, 22 Nov 2019 03:38:16 +0100 Subject: [PATCH 1/8] %p --- inputs.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/inputs.py b/inputs.py index 4607791..a01c2fd 100644 --- a/inputs.py +++ b/inputs.py @@ -31,6 +31,9 @@ def input_int(): if (choice == 3): return str(0) +def input_ptr(): + return "(void *)({})".format(input_int()) + def input_char(): choice = random.choice([0, 1]) if (choice == 0): @@ -41,7 +44,7 @@ def input_char(): def random_arg(): format = "%" data = [] - choices = ["s", "c", "i", "d", "x", "X", "%", "u"] + choices = ["s", "c", "i", "d", "x", "X", "%", "u", "p"] width = "" size = "" @@ -57,14 +60,14 @@ def random_arg(): if (random.random() > .5): if (random.random() > .8): size = ".*" - if (type != "%" and type != "c"): + if (type != "%" and type != "c" and type != "p"): data.append(str(random.randint(-10, 10))) else: size = "." + str(random.randint(0, 5)) choice = random.choice([0, 1, 2]) if (choice == 0): flags = "" - elif (choice == 1): + elif (choice == 1 or type == "p"): flags = "-" else: flags = "0" @@ -100,5 +103,9 @@ def random_arg(): format += width format += size data.append(input_int()) + if (type == "p"): + format += flags + format += width + data.append(input_ptr()) format += type return (format, data) From 63ec009ea057b99762724b53c8ea44a7664d4685 Mon Sep 17 00:00:00 2001 From: cchudant Date: Fri, 22 Nov 2019 03:40:38 +0100 Subject: [PATCH 2/8] %p conversion readme update --- ReadMe.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/ReadMe.md b/ReadMe.md index 29fab69..4c59725 100644 --- a/ReadMe.md +++ b/ReadMe.md @@ -2,8 +2,6 @@ This project is a script that generate thousands of tests for the school 42 project ft_printf. -It doesn't test %p flag. - By **tmarx** ## Usage ```sh From 84fdda22db45ac9eb402cc332341e39c6842a270 Mon Sep 17 00:00:00 2001 From: cchudant Date: Mon, 25 Nov 2019 15:17:48 +0100 Subject: [PATCH 3/8] bonuses --- .vimrc | 3 + a.out | Bin 0 -> 8432 bytes inputs.py | 210 ++++++++++++++++++++++++++++++++++++++---------- main.c | 10 +++ main_template.c | 2 + run.py | 18 ++++- 6 files changed, 198 insertions(+), 45 deletions(-) create mode 100644 .vimrc create mode 100755 a.out create mode 100644 main.c diff --git a/.vimrc b/.vimrc new file mode 100644 index 0000000..2fd03e6 --- /dev/null +++ b/.vimrc @@ -0,0 +1,3 @@ +set noet +set ts=4 +set sw=4 diff --git a/a.out b/a.out new file mode 100755 index 0000000000000000000000000000000000000000..fe53c7d32fab601f1b53f19e7f4ecad63db49719 GIT binary patch literal 8432 zcmeHM-%C_M6h1et#7x(h=r=cO!+KB)lU@WjTwF;?Qz?R&T=$v_cURea7ZnON#9$G@ zm--7LdI;*Fpk6DeUW)#Npv1sHs0R^h`_8>HyLWfXcVP}3&yP9t-I;G^V4V51`Qy)S zBBO>Vw}Xh9prM^a3uMA0IslD9g&2(VMXyJ%T;^=K80FzVBgSdP2ZR`jUK=Sd@%o3# zb0lMojW8VAC7XqCty#BJTZM-SFkV8HAg)zD+gi#6Lm?bD8+VGSO1y-`Q{Pvy>QE=~ zRJ)HSCM|o~%Alwc&z5)xB>>0Fdr_*!H}1HZWcrpYsKmP`@s7)Oj)PK$jRqmcr_xS| zz)HL)60c5za9oKI#1|r)o=K(?BAK3;^6<-l-{%sK*ANTGTjB9KS%nJG8ySgk4=Gp= zW$Q$(m%uu~8ZKfBk+y|1mx@o>V%p987f-?PdgJ~|`1ka_Clf;0V_V^c(4XrSZyX2l zcpV4h(!Lt#zjQI$+pqS7Susz6?4OMfa{>~ye9q;6;5%VhEqNwppU=+?IRA$HlQp7}!-109 z=p#R)Qrc<;Gy|Fe&46Y=GoTsJ3}^;41DXNNfM!55u+150ZVB .5): + if (type in "cs"): + size_modifier = "l" + elif (random.random() > .5): + size_modifier = "h" * random.choice([1, 2]) + else: + size_modifier = "l" * random.choice([1, 2]) + + width = "" if (random.random() > .5): if (random.random() > .8): width = "*" data.append(str(random.randint(-10, 10))) else: width = str(random.randint(1, 20)) + + size = "" if (random.random() > .5): if (random.random() > .8): size = ".*" @@ -64,37 +153,62 @@ def random_arg(): data.append(str(random.randint(-10, 10))) else: size = "." + str(random.randint(0, 5)) + + flags = "" + + if (type in "xXfge" and tests["bonus_hashtag"] and random.random() > .5): + flags += "#" + choice = random.choice([0, 1, 2]) - if (choice == 0): - flags = "" - elif (choice == 1 or type == "p"): - flags = "-" - else: - flags = "0" + if (choice == 1 or type in "psc"): + flags += "-" + elif (choice == 2): + flags += "0" + + choice = random.choice([0, 1, 2]) + if (type in "di" and tests["bonus_space"] and choice == 1): + flags += "#" + elif (type in "di" and tests["bonus_plus"] and choice == 2): + flags += "+" + if (type == "s"): - format += flags.replace("0", "") + format += flags format += width format += size - data.append(input_string()) + if (tests["bonus_size_modifier_wide_char"]): + format += size_modifier + data.append(input_string( + size_modifier if tests["bonus_size_modifier_wide_char"] else "" + )) if (type == "c"): - format += flags.replace("0", "") + format += flags format += width - data.append(input_char()) + if (tests["bonus_size_modifier_wide_char"]): + format += size_modifier + data.append(input_char( + size_modifier if tests["bonus_size_modifier_wide_char"] else "" + )) if (type == "i" or type == "d"): format += flags format += width format += size - data.append(input_int()) + if (tests["bonus_size_modifier"]): + format += size_modifier + data.append(input_int(size_modifier)) if (type == "x"): format += flags format += width format += size - data.append(input_int()) + if (tests["bonus_size_modifier"]): + format += size_modifier + data.append(input_uint(size_modifier)) if (type == "X"): format += flags format += width format += size - data.append(input_int()) + if (tests["bonus_size_modifier"]): + format += size_modifier + data.append(input_uint(size_modifier)) if (type == "%"): data = [] data.append("") @@ -102,10 +216,22 @@ def random_arg(): format += flags format += width format += size - data.append(input_int()) + if (tests["bonus_size_modifier"]): + format += size_modifier + data.append(input_uint(size_modifier)) if (type == "p"): format += flags format += width data.append(input_ptr()) + if (type == "f"): + format += flags + format += width + format += size + data.append(input_float()) + if (type == "e"): + format += flags + format += width + format += size + data.append(input_float()) format += type return (format, data) diff --git a/main.c b/main.c new file mode 100644 index 0000000..86aa23a --- /dev/null +++ b/main.c @@ -0,0 +1,10 @@ +#include +#include +int main(void) +{ + printf("ret = %d\n", printf("sssssss = %ls\n", L"Ō")); + wchar_t *s = L"Ō"; + printf("d = %ld\n", sizeof(wchar_t)); + printf("sd = %.4x\n", *s); + +} diff --git a/main_template.c b/main_template.c index 19ff76a..cccc73d 100644 --- a/main_template.c +++ b/main_template.c @@ -1,4 +1,6 @@ #include +#include +#include int ft_printf(const char *, ...); diff --git a/run.py b/run.py index bcf15eb..8344620 100644 --- a/run.py +++ b/run.py @@ -5,6 +5,18 @@ N = 1000 M = 20 + +TESTS = { + "bonus_size_modifier": True, + "bonus_size_modifier_wide_char": False, + "bonus_float_conversion_f": False, + "bonus_float_conversion_e": False, + "bonus_float_conversion_g": False, + "bonus_hashtag": True, + "bonus_space": False, + "bonus_plus": False, +} + COMP = "gcc -Wall -Wextra -Werror -g3 -fsanitize=address " tests = [] @@ -27,7 +39,7 @@ def function_content(): if (random.random() < .6): format += inputs.random_string(random.randint(1, 5)) else: - temp = inputs.random_arg() + temp = inputs.random_arg(TESTS) format += temp[0] for arg in temp[1]: args.append(arg) @@ -75,8 +87,8 @@ def diff(): ok = True print("Comparing outputs:") print() - ftprintf_output = open("ftprintf_output", "r").readlines() - printf_output = open("printf_output", "r").readlines() + ftprintf_output = open("ftprintf_output", "r", encoding="ISO-8859-1").readlines() + printf_output = open("printf_output", "r", encoding="ISO-8859-1").readlines() for i in range(len(tests)): if (ftprintf_output[i] != printf_output[i]): ok = False From 75ab5d9002612c35cd1adf768a73e9eefcc6e47e Mon Sep 17 00:00:00 2001 From: cchudant Date: Mon, 25 Nov 2019 15:33:01 +0100 Subject: [PATCH 4/8] fix # space and + --- inputs.py | 2 +- run.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/inputs.py b/inputs.py index e3be203..da30902 100644 --- a/inputs.py +++ b/inputs.py @@ -167,7 +167,7 @@ def random_arg(tests): choice = random.choice([0, 1, 2]) if (type in "di" and tests["bonus_space"] and choice == 1): - flags += "#" + flags += " " elif (type in "di" and tests["bonus_plus"] and choice == 2): flags += "+" diff --git a/run.py b/run.py index 8344620..447ec03 100644 --- a/run.py +++ b/run.py @@ -13,8 +13,8 @@ "bonus_float_conversion_e": False, "bonus_float_conversion_g": False, "bonus_hashtag": True, - "bonus_space": False, - "bonus_plus": False, + "bonus_space": True, + "bonus_plus": True, } COMP = "gcc -Wall -Wextra -Werror -g3 -fsanitize=address " From 66ab20c3fdfcc1a0f3dc008459a4dca7f4d3749b Mon Sep 17 00:00:00 2001 From: cchudant Date: Wed, 27 Nov 2019 16:44:10 +0100 Subject: [PATCH 5/8] some cleanup --- .vimrc | 3 --- a.out | Bin 8432 -> 0 bytes inputs.py | 13 +++++-------- main.c | 10 ---------- main_template.c | 6 +++++- 5 files changed, 10 insertions(+), 22 deletions(-) delete mode 100644 .vimrc delete mode 100755 a.out delete mode 100644 main.c diff --git a/.vimrc b/.vimrc deleted file mode 100644 index 2fd03e6..0000000 --- a/.vimrc +++ /dev/null @@ -1,3 +0,0 @@ -set noet -set ts=4 -set sw=4 diff --git a/a.out b/a.out deleted file mode 100755 index fe53c7d32fab601f1b53f19e7f4ecad63db49719..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 8432 zcmeHM-%C_M6h1et#7x(h=r=cO!+KB)lU@WjTwF;?Qz?R&T=$v_cURea7ZnON#9$G@ zm--7LdI;*Fpk6DeUW)#Npv1sHs0R^h`_8>HyLWfXcVP}3&yP9t-I;G^V4V51`Qy)S zBBO>Vw}Xh9prM^a3uMA0IslD9g&2(VMXyJ%T;^=K80FzVBgSdP2ZR`jUK=Sd@%o3# zb0lMojW8VAC7XqCty#BJTZM-SFkV8HAg)zD+gi#6Lm?bD8+VGSO1y-`Q{Pvy>QE=~ zRJ)HSCM|o~%Alwc&z5)xB>>0Fdr_*!H}1HZWcrpYsKmP`@s7)Oj)PK$jRqmcr_xS| zz)HL)60c5za9oKI#1|r)o=K(?BAK3;^6<-l-{%sK*ANTGTjB9KS%nJG8ySgk4=Gp= zW$Q$(m%uu~8ZKfBk+y|1mx@o>V%p987f-?PdgJ~|`1ka_Clf;0V_V^c(4XrSZyX2l zcpV4h(!Lt#zjQI$+pqS7Susz6?4OMfa{>~ye9q;6;5%VhEqNwppU=+?IRA$HlQp7}!-109 z=p#R)Qrc<;Gy|Fe&46Y=GoTsJ3}^;41DXNNfM!55u+150ZVB .5): + if (random.random() > .5 and type not in "%"): if (random.random() > .8): width = "*" data.append(str(random.randint(-10, 10))) @@ -146,11 +146,10 @@ def random_arg(tests): width = str(random.randint(1, 20)) size = "" - if (random.random() > .5): + if (random.random() > .5 and type not in "%cp"): if (random.random() > .8): size = ".*" - if (type != "%" and type != "c" and type != "p"): - data.append(str(random.randint(-10, 10))) + data.append(str(random.randint(-10, 10))) else: size = "." + str(random.randint(0, 5)) @@ -188,7 +187,7 @@ def random_arg(tests): data.append(input_char( size_modifier if tests["bonus_size_modifier_wide_char"] else "" )) - if (type == "i" or type == "d"): + if (type in "id"): format += flags format += width format += size @@ -209,9 +208,6 @@ def random_arg(tests): if (tests["bonus_size_modifier"]): format += size_modifier data.append(input_uint(size_modifier)) - if (type == "%"): - data = [] - data.append("") if (type == "u"): format += flags format += width @@ -233,5 +229,6 @@ def random_arg(tests): format += width format += size data.append(input_float()) + format += type return (format, data) diff --git a/main.c b/main.c deleted file mode 100644 index 86aa23a..0000000 --- a/main.c +++ /dev/null @@ -1,10 +0,0 @@ -#include -#include -int main(void) -{ - printf("ret = %d\n", printf("sssssss = %ls\n", L"Ō")); - wchar_t *s = L"Ō"; - printf("d = %ld\n", sizeof(wchar_t)); - printf("sd = %.4x\n", *s); - -} diff --git a/main_template.c b/main_template.c index cccc73d..92243ed 100644 --- a/main_template.c +++ b/main_template.c @@ -4,8 +4,12 @@ int ft_printf(const char *, ...); +/* +** : wide character (bonus) +*/ + int main() { $$$1 - return (0); + return (0); } From e3b596f3605029f95beb46300f00728e0aa19bd6 Mon Sep 17 00:00:00 2001 From: cchudant Date: Fri, 29 Nov 2019 07:38:44 +0100 Subject: [PATCH 6/8] update readme --- ReadMe.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/ReadMe.md b/ReadMe.md index 4c59725..c8a475a 100644 --- a/ReadMe.md +++ b/ReadMe.md @@ -2,6 +2,8 @@ This project is a script that generate thousands of tests for the school 42 project ft_printf. +To enable bonuses, edit the `TESTS` dictionary in `run.py`. + By **tmarx** ## Usage ```sh From ab5b1675d98969801114d125c03c01e267d19802 Mon Sep 17 00:00:00 2001 From: cchudant Date: Fri, 29 Nov 2019 07:39:48 +0100 Subject: [PATCH 7/8] bonus defaults --- run.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/run.py b/run.py index 447ec03..7f370ac 100644 --- a/run.py +++ b/run.py @@ -7,14 +7,14 @@ M = 20 TESTS = { - "bonus_size_modifier": True, + "bonus_size_modifier": False, "bonus_size_modifier_wide_char": False, "bonus_float_conversion_f": False, "bonus_float_conversion_e": False, "bonus_float_conversion_g": False, - "bonus_hashtag": True, - "bonus_space": True, - "bonus_plus": True, + "bonus_hashtag": False, + "bonus_space": False, + "bonus_plus": False, } COMP = "gcc -Wall -Wextra -Werror -g3 -fsanitize=address " From d7d34f1293f15259586a39cf60678fb7be6cccae Mon Sep 17 00:00:00 2001 From: cchudant Date: Fri, 29 Nov 2019 13:55:29 +0100 Subject: [PATCH 8/8] fix unicode --- inputs.py | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/inputs.py b/inputs.py index 216b043..2c9d11e 100644 --- a/inputs.py +++ b/inputs.py @@ -176,45 +176,53 @@ def random_arg(tests): format += size if (tests["bonus_size_modifier_wide_char"]): format += size_modifier - data.append(input_string( - size_modifier if tests["bonus_size_modifier_wide_char"] else "" - )) + data.append(input_string(size_modifier)) + else: + data.append(input_string("")) if (type == "c"): format += flags format += width if (tests["bonus_size_modifier_wide_char"]): format += size_modifier - data.append(input_char( - size_modifier if tests["bonus_size_modifier_wide_char"] else "" - )) + data.append(input_char(size_modifier)) + else: + data.append(input_char("")) if (type in "id"): format += flags format += width format += size if (tests["bonus_size_modifier"]): format += size_modifier - data.append(input_int(size_modifier)) + data.append(input_int(size_modifier)) + else: + data.append(input_int("")) if (type == "x"): format += flags format += width format += size if (tests["bonus_size_modifier"]): format += size_modifier - data.append(input_uint(size_modifier)) + data.append(input_uint(size_modifier)) + else: + data.append(input_uint("")) if (type == "X"): format += flags format += width format += size if (tests["bonus_size_modifier"]): format += size_modifier - data.append(input_uint(size_modifier)) + data.append(input_uint(size_modifier)) + else: + data.append(input_uint("")) if (type == "u"): format += flags format += width format += size if (tests["bonus_size_modifier"]): format += size_modifier - data.append(input_uint(size_modifier)) + data.append(input_uint(size_modifier)) + else: + data.append(input_uint("")) if (type == "p"): format += flags format += width