Browse Source

Bugfix mutator and 0 len expr

Yann Weber 6 years ago
parent
commit
cb1b9531b4
2 changed files with 5 additions and 3 deletions
  1. 2
    0
      gte/__main__.py
  2. 3
    3
      gte/mutator.py

+ 2
- 0
gte/__main__.py View File

@@ -112,6 +112,8 @@ if 'pool_size' in args:
112 112
         #        for _ in range(args.pool_size)]
113 113
     else:
114 114
         prog = rpnlib.RpnExpr.from_string(args.prog)
115
+        if len(prog) == 0:
116
+            prog = rpnlib.RpnExpr([rpnlib.RpnSymbol.from_string('0')])
115 117
         progs = [prog]
116 118
         progs += [mutate(prog, force=True) for _ in range(args.pool_size-1)]
117 119
 

+ 3
- 3
gte/mutator.py View File

@@ -61,14 +61,14 @@ def mutadd(expr):
61 61
     return expr
62 62
 
63 63
 def mutdel(expr):
64
-    if len(expr) == 1:
64
+    if len(expr) <= 1:
65 65
         return mutadd(expr)
66 66
     pos = randint(0, len(expr)-1)
67 67
     del(expr[pos])
68 68
     return expr
69 69
 
70 70
 def mutupdtype(expr):
71
-    if len(expr) == 1:
71
+    if len(expr) <= 1:
72 72
         pos = 0
73 73
     else:
74 74
         pos = randint(0, len(expr) - 1)
@@ -78,7 +78,7 @@ def mutupdtype(expr):
78 78
     return expr
79 79
 
80 80
 def mutupdval(expr):
81
-    if len(expr) == 1:
81
+    if len(expr) <= 1:
82 82
         pos = 0
83 83
     else:
84 84
         pos = randint(0, len(expr) - 1)

Loading…
Cancel
Save