From 582623711ce6b7ee40c8152b11ec8279937dc362 Mon Sep 17 00:00:00 2001 From: zixi2 Date: Mon, 5 Dec 2022 04:52:59 -0600 Subject: [PATCH] add count_test, filter_param, ctest_indent --- core/generate_ctest/count_test_on_each_param.py | 16 ++++++++++++++++ core/generate_ctest/ctest_indent.py | 7 +++++++ core/generate_ctest/filter_param_by_test_num.py | 16 ++++++++++++++++ 3 files changed, 39 insertions(+) create mode 100644 core/generate_ctest/count_test_on_each_param.py create mode 100644 core/generate_ctest/ctest_indent.py create mode 100644 core/generate_ctest/filter_param_by_test_num.py diff --git a/core/generate_ctest/count_test_on_each_param.py b/core/generate_ctest/count_test_on_each_param.py new file mode 100644 index 00000000..909aae64 --- /dev/null +++ b/core/generate_ctest/count_test_on_each_param.py @@ -0,0 +1,16 @@ +## By Oscar Chen and Chris Shen from CS527, Fall 2022 +## This program will generate a "{project}_test_num_on_param.txt" file in same directory that records the number of test methods related to each param. +## In each line of the generated file, the number of tests methods always comes before the param name +## File required: openctest/data/ctest_mapping/opensource-{project}.json +## openctest/core/generate_value/{project}-generated-values.tsv +import json +from program_input import p_input +j = json.load(open("../../data/ctest_mapping/opensource-"+p_input["project"]+".json")) +c = {} +for p in open("../generate_value/"+p_input["project"]+"-generated-values.tsv").readlines(): + key = p.split("\t")[0] + if (key in j.keys()): + c.update({key: len(j[key])}) +with open(p_input["project"]+"_test_num_on_param.txt", "w") as outfile: + for k in c.keys(): + outfile.write(str(c[k])+"\t"+k+"\n") \ No newline at end of file diff --git a/core/generate_ctest/ctest_indent.py b/core/generate_ctest/ctest_indent.py new file mode 100644 index 00000000..adfc5848 --- /dev/null +++ b/core/generate_ctest/ctest_indent.py @@ -0,0 +1,7 @@ +## By Oscar Chen and Chris Shen from CS527, Fall 2022 +## This program helps create an indented version of ctests-{project}.json +## Fire required: openctest/core/generate_ctest/ctest_mapping/ctests-{project}.json +import json +from program_input import p_input +j = json.load(open("ctest_mapping/ctests-"+p_input["project"]+".json")) +json.dump(j, open("ctest_mapping/ctests-"+p_input["project"]+"-indent.json", "w"), indent=4) \ No newline at end of file diff --git a/core/generate_ctest/filter_param_by_test_num.py b/core/generate_ctest/filter_param_by_test_num.py new file mode 100644 index 00000000..decf06fb --- /dev/null +++ b/core/generate_ctest/filter_param_by_test_num.py @@ -0,0 +1,16 @@ +## By Oscar Chen and Chris Shen from CS527, Fall 2022 +## This program will filter the params with number of test reference in between min and max +## The selected params will be saved in {project}.tsv in same directory +## Fill free to modify min and max to what you need +## File required: openctest/data/ctest_mapping/opensource-{project}.json +## openctest/core/generate_value/{project}-generated-values.tsv +import json +from program_input import p_input +min = 0 +max = 50 +j = json.load(open("../../data/ctest_mapping/opensource-"+p_input["project"]+".json")) +w = open(p_input["project"]+".tsv", "w") +for p in open("../generate_value/"+p_input["project"]+"-generated-values.tsv").readlines(): + key = p.split("\t")[0] + if key in j.keys() and (len(j[key]) >= min) and (len(j[key]) < max): + w.write(p) \ No newline at end of file