Ejemplo n.º 1
0
 def test_Split(self):
     for lcl, py in self.lists.items():
         for _ in range(10):
             t = choice(py)
             i = py.index(t)
             left, right = py[:i], py[i + 1:]
             self.singleSolved(f"Split({lcl},{t},?left,?right)",
                               left=toLCL(left),
                               right=toLCL(right))
Ejemplo n.º 2
0
 def test_TakeDrop(self):
     for lcl, py in self.lists.items():
         for i in range(len(py) + 1):
             take, drop = py[:i], py[i:]
             lcl_take, lcl_drop = toLCL(take), toLCL(drop)
             self.singleSolved(f"Take({lcl},{i},?taken)", taken=lcl_take)
             self.singleSolved(f"Drop({lcl},{i},?dropped)",
                               dropped=lcl_drop)
         self.noSolution(f"Take({lcl},{i+1},?taken)")
         self.singleSolved(f"Drop({lcl},{i+1},?dropped)", dropped="[]")
Ejemplo n.º 3
0
    def test_Choice(self):

        py = ["1", "2", "3", "4", "5", "6", "7"]
        pyf = []
        for i in range(len(py)):
            for j in range(i + 1, len(py)):
                for k in range(j + 1, len(py)):
                    pyf.append([py[i], py[j], py[k]])
        lclf = toLCL(pyf)
        lcl = toLCL(py)

        self.singleSolved(f"Choice({lcl},3,?x)", x=lclf)
Ejemplo n.º 4
0
    def test_Join(self):
        for i in range(20):
            (lcl1, py1), (lcl2, py2) = choice(list(
                self.lists.items())), choice(list(self.lists.items()))
            py3 = py1 + py2
            lcl3 = toLCL(py3)
            self.singleSolved(f"Join({lcl1},{lcl2},?x)", x=lcl3)

        for i in range(20):
            k = choices(list(self.lists.items()), k=5)
            lcls, pys = list(zip(*k))
            pyf = []
            for py in pys:
                pyf += py
            lclFinal = toLCL(pyf)
            lclBegin = toLCL(lcls)
            self.singleSolved(f"Join({lclBegin},?x)", x=lclFinal)
Ejemplo n.º 5
0
    def test_Appended(self):
        for lcl, py in self.lists.items():
            x = '"Apple, 5$ a share"'
            pyf = py + [x]
            lclf = toLCL(pyf)
            self.singleSolved(f"Appended({x},{lcl},?new)", new=lclf)

        self.singleSolved(f"Appended({x},[],?new)", new=f"[{x}]")
Ejemplo n.º 6
0
 def test_Sublist(self):
     for lcl, py in self.lists.items():
         i = randint(0, len(py) - 1)
         j = randint(i, len(py) - 1)
         pyf = py[i:j]
         lclf = toLCL(pyf)
         self.singleSolved(f"Sublist({lcl},{i},{j},?sub)", sub=lclf)
         if pyf:
             self.singleSolved(f"Sublist({lcl},?i,?j,{lclf})", i=i, j=j)
Ejemplo n.º 7
0
 def test_ZipUnzip(self):
     self.singleSolved("Zip([1,2,3],[A,B,\"Charlie\"],?x)",
                       x=toLCL(["(1/A)", "(2/B)", '(3/"Charlie")']))
     self.singleSolved("Zip(?x,?y,[(1/2),(3/4),(G/H)])",
                       x="[1,3,G]",
                       y="[2,4,H]")
     self.singleSolved(
         "Unzip([[1,2,3],[4,5,6,G,H],[A,B,\"Hello You There\"]],2,?x)",
         x='[3,6,"Hello You There"]')
Ejemplo n.º 8
0
 def test_Removed(self):
     for lcl, py in self.lists.items():
         for x in py:
             pyf = py.copy()
             pyf.remove(x)
             lclf = toLCL(pyf)
             self.singleSolved(f"Removed({x},{lcl},?without)", without=lclf)
         x = "567"
         self.noSolution(f"Removed({x},{lcl},?without)")
Ejemplo n.º 9
0
 def test_Cartesian(self):
     py1 = ["1", "2", "3", "4"]
     py2 = ["A", "B", "C"]
     pyf = []
     for a in py1:
         for b in py2:
             pyf.append([a, b])
     lclf = toLCL(pyf)
     self.singleSolved(f"Cartesian({toLCL(py1)},{toLCL(py2)},?pairs)",
                       pairs=lclf)
Ejemplo n.º 10
0
    def test_IndexChange(self):
        for lcl, py in self.lists.items():
            self.multipleSolved(f"Index(?i,{lcl},?x)",
                                i=tuple(map(str, range(len(py)))),
                                x=tuple(py))
        for lcl, py in self.lists.items():
            for i in range(len(py)):
                self.singleSolved(f"Index({i},{lcl},?x)", x=py[i])
            self.noSolution(f"Index({i+1},{lcl},?x)")
        for lcl, py in self.lists.items():
            for x in py:
                self.singleSolved(f"Index(?i,{lcl},{x})", i=py.index(x))

        _l = "[1,2,3,2,6]"
        self.multipleSolved(f"Index(?i,{_l},2)", i=('1', '3'))

        for lcl, py in self.lists.items():
            for i in range(len(py)):
                pyf = py.copy()
                x = choice(["T(8)", "7", "[1,2,3,4,5]", "Apple"])
                pyf[i] = x
                lclf = toLCL(pyf)
                self.singleSolved(f"Change({lcl},{i},{x},?changed)",
                                  changed=lclf)
Ejemplo n.º 11
0
 def test_PowerSet(self):
     py = ["1", "2", "A", "6", "B", "9"]
     lcl = toLCL(py)
     lclf = toLCL(map(list, powerset(py)))
     self.singleSolved(f"PowerSet({lcl},?p)", p=lclf)
Ejemplo n.º 12
0
 def test_Duplicate(self):
     self.singleSolved("Duplicate([1,2,3],5,?x)",
                       x=toLCL(['1', '2', '3'] * 5))
     self.singleSolved("Duplicate([[]],5,?x)", x=toLCL([[]] * 5))