def test_include_taxa(): # The taxon "var/assignment/explicit/single" is directly featured by assignment.py and # collatz.py, but only indirectly by the other programs, which therefore cannot be # included in the result. Note that this behavior contrasts with that of exclude_taxa. dbf = ProgramFilter(db) dbf.include_programs( dbf.programs_of_taxa({"var/assignment/explicit/single"})) print(dbf.selected_programs) assert dbf.selected_programs == {"assignment.py", "collatz.py"} # "operator/arithmetic/addition" is directly featured by collatz.py only. Therefore, # including this taxon keeps only collatz.py. dbf = ProgramFilter(db) dbf.include_programs(dbf.programs_of_taxa({"operator/arithmetic/addition" })) print(dbf.selected_programs) assert dbf.selected_programs == {"collatz.py"} # "flow/conditional" is featured by collatz.py, fizzbuzz.py, and indirectly by # is_even.py. Therefore, including this taxon keeps only the former two. dbf = ProgramFilter(db) dbf.include_programs(dbf.programs_of_taxa({"flow/conditional"})) print(dbf.selected_programs) assert dbf.selected_programs == {"collatz.py", "fizzbuzz.py"} # "type/sequence/string/literal" is directly featured by fizzbuzz.py only. Therefore, including # this taxon keeps only fizzbuzz.py dbf = ProgramFilter(db) dbf.include_programs(dbf.programs_of_taxa({"type/sequence/string/literal" })) print(dbf.selected_programs) assert dbf.selected_programs == {"fizzbuzz.py"}
def test_programs_of_taxa(): dbf = ProgramFilter(db) taxa = {"X/S/M/L/R/D/A", "X/S/M/L/R/D", "non_existing_taxon"} programs = dbf.programs_of_taxa(taxa, follow=False) print(sorted(programs)) for (db_program, db_program_data) in db["programs"].items(): if taxa.intersection(db_program_data["taxa"]): assert db_program in programs else: assert db_program not in programs
def test_programs_of_taxa(): dbf = ProgramFilter(db) taxa = {"var/assignment/explicit/single"} # The taxon "var/assignment/explicit/single" is featured by assignment.py and collatz.py. # This corresponds to follow=False. It is indirectly featured by fizzbuzz.py (which imports # collatz.py) and by is_even.py (which imports fizzbuzz.py). Their addition corresponds # to follow=True. programs = dbf.programs_of_taxa(taxa) print(set(programs)) assert set(programs) == {"assignment.py", "collatz.py"} programs = dbf.programs_of_taxa(taxa, follow=True) print(set(programs)) assert set(programs) == { "assignment.py", "collatz.py", "fizzbuzz.py", "is_even.py", }
def test_exclude_taxa(): # The taxon "var/assignment/explicit/single" is featured by assignment.py and collatz.py. It # is indirectly featured by fizzbuzz.py (which imports collatz.py) and by is_even.py # (which imports fizzbuzz.py). Therefore, excluding this taxon excludes all four programs. dbf = ProgramFilter(db) dbf.exclude_programs(dbf.programs_of_taxa( {"var/assignment/explicit/single"}), follow=True) print(dbf.selected_programs) assert dbf.selected_programs == set() # "operator/arithmetic/addition" is featured by collatz.py, and indirectly by fizzbuzz.py # and is_even.py. Therefore, excluding this taxon keeps only assignment.py. dbf = ProgramFilter(db) dbf.exclude_programs(dbf.programs_of_taxa( {"call/subroutine/builtin/print"}), follow=True) print(dbf.selected_programs) assert dbf.selected_programs == {"assignment.py"} # "flow/conditional" is featured by collatz.py, fizzbuzz.py, and indirectly by # is_even.py. Therefore, excluding this taxon keeps only assignment.py. dbf = ProgramFilter(db) dbf.exclude_programs(dbf.programs_of_taxa({"flow/conditional"}), follow=True) print(dbf.selected_programs) assert dbf.selected_programs == {"assignment.py"} # "type/sequence/string/literal" is featured by fizzbuzz.py, and indirectly by is_even.py. # Therefore, excluding this taxon keeps only assignment.py and collatz.py dbf = ProgramFilter(db) dbf.exclude_programs(dbf.programs_of_taxa({"type/sequence/string/literal" }), follow=True) print(dbf.selected_programs) assert dbf.selected_programs == {"assignment.py", "collatz.py"}