Skip to content

Commit

Permalink
More cleanup + more list operations test.
Browse files Browse the repository at this point in the history
  • Loading branch information
bladecoder committed Sep 28, 2023
1 parent f734a45 commit 5b2da13
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 14 deletions.
Expand Up @@ -683,7 +683,7 @@ public RTObject call(List<RTObject> parameters) throws Exception {
List<Value<?>> coercedParams = coerceValuesToSingleType(parameters);
ValueType coercedType = coercedParams.get(0).getValueType();

// Originally CallType gets a type parameter taht is used to do some
// Originally CallType gets a type parameter that is used to do some
// casting, but we can do without.
if (coercedType == ValueType.Int) {
return callType(coercedParams);
Expand Down Expand Up @@ -731,7 +731,7 @@ Value<?> callBinaryListOperation(List<RTObject> parameters) throws StoryExceptio
"Can not call use '" + name + "' operation on " + v1.getValueType() + " and " + v2.getValueType());
}

Value<?> callListIncrementOperation(List<RTObject> listIntParams) throws StoryException, Exception {
Value<?> callListIncrementOperation(List<RTObject> listIntParams) {
ListValue listVal = (ListValue) listIntParams.get(0);
IntValue intVal = (IntValue) listIntParams.get(1);

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/bladecoder/ink/runtime/StoryState.java
Expand Up @@ -613,7 +613,7 @@ void pushEvaluationStack(RTObject obj) {

if (rawList.getOriginNames() != null) {

if (rawList.getOrigins() == null) rawList.setOrigins(new ArrayList<ListDefinition>());
if (rawList.getOrigins() == null) rawList.setOrigins(new ArrayList<>());

rawList.getOrigins().clear();

Expand Down
12 changes: 2 additions & 10 deletions src/main/java/com/bladecoder/ink/runtime/VariablesState.java
Expand Up @@ -39,10 +39,6 @@ public interface VariableChanged {
this.listDefsOrigin = listDefsOrigin;
}

CallStack getCallStack() {
return callStack;
}

void setCallStack(CallStack callStack) {
this.callStack = callStack;
}
Expand Down Expand Up @@ -92,10 +88,6 @@ public void assign(VariableAssignment varAss, RTObject value) throws Exception {
}
}

ListDefinitionsOrigin getLists() {
return listDefsOrigin;
}

void applyPatch() {
for (Entry<String, RTObject> namedVar : getPatch().getGlobals().entrySet()) {
globalVariables.put(namedVar.getKey(), namedVar.getValue());
Expand Down Expand Up @@ -402,11 +394,11 @@ boolean globalVariableExistsWithName(String name) {
|| (defaultGlobalVariables != null && defaultGlobalVariables.containsKey(name));
}

public StatePatch getPatch() {
StatePatch getPatch() {
return patch;
}

public void setPatch(StatePatch patch) {
void setPatch(StatePatch patch) {
this.patch = patch;
}
}
13 changes: 12 additions & 1 deletion src/test/java/com/bladecoder/ink/runtime/test/ListSpecTest.java
Expand Up @@ -92,7 +92,7 @@ public void testEmptyListOriginAfterAssignment() throws Exception {
Assert.assertEquals("a, b, c\n", story.continueMaximally());
}

// @Test
@Test
public void testListRange() throws Exception {

String json = TestUtils.getJsonString("inkfiles/lists/list-range.ink.json");
Expand Down Expand Up @@ -120,4 +120,15 @@ public void testBugAddingElement() throws Exception {
s = story.continueMaximally();
Assert.assertEquals("OK\n", s);
}

@Test
public void testMoreListOperations2() throws Exception {

String json = TestUtils.getJsonString("inkfiles/lists/more-list-operations2.ink.json");
Story story = new Story(json);

Assert.assertEquals(
"a1, b1, c1\na1\na1, b2\ncount:2\nmax:c2\nmin:a1\ntrue\ntrue\nfalse\nempty\na2\na2, b2, c2\nrange:a1, b2\na1\nsubtract:a1, c1\nrandom:a1\nlistinc:b1\n",
story.continueMaximally());
}
}
43 changes: 43 additions & 0 deletions src/test/resources/inkfiles/lists/more-list-operations2.ink
@@ -0,0 +1,43 @@
LIST list1 = (a1), b1, c1
LIST list2 = a2, b2, c2
LIST list3 = a3, b3, c3
VAR vlist = ()

{LIST_ALL(list1)}
{list1}

~list2 += a1
~list2 += b2

{list2}
count:{LIST_COUNT(list2)}

~list2 += c2

max:{LIST_MAX(list2)}
min:{LIST_MIN(list2)}

// Equality
~temp t = list2
{t == list2}
{t == (a1, b2, c2)}
{t != list2}

//emptiness
{list3: not empty| empty}

~vlist = (a2)
{ vlist }
{ LIST_ALL(vlist) }

range:{ LIST_RANGE(list2, 1, 2)}
{ LIST_RANGE(list2, a1, a3)}

subtract:{(a1,b1,c1) - (b1)}

~ SEED_RANDOM(10)
random:{LIST_RANDOM(t)}

listinc:{(a1) + 1}


@@ -0,0 +1 @@
{"inkVersion":21,"root":[["ev",{"VAR?":"list1"},"LIST_ALL","out","/ev","\n","ev",{"VAR?":"list1"},"out","/ev","\n","ev",{"VAR?":"list2"},{"VAR?":"a1"},"+",{"VAR=":"list2","re":true},"/ev","ev",{"VAR?":"list2"},{"VAR?":"b2"},"+",{"VAR=":"list2","re":true},"/ev","ev",{"VAR?":"list2"},"out","/ev","\n","^count:","ev",{"VAR?":"list2"},"LIST_COUNT","out","/ev","\n","ev",{"VAR?":"list2"},{"VAR?":"c2"},"+",{"VAR=":"list2","re":true},"/ev","^max:","ev",{"VAR?":"list2"},"LIST_MAX","out","/ev","\n","^min:","ev",{"VAR?":"list2"},"LIST_MIN","out","/ev","\n","ev",{"VAR?":"list2"},"/ev",{"temp=":"t"},"ev",{"VAR?":"t"},{"VAR?":"list2"},"==","out","/ev","\n","ev",{"VAR?":"t"},{"list":{"list1.a1":1,"list2.b2":2,"list2.c2":3}},"==","out","/ev","\n","ev",{"VAR?":"t"},{"VAR?":"list2"},"!=","out","/ev","\n","ev",{"VAR?":"list3"},"/ev",[{"->":".^.b","c":true},{"b":["^ not empty",{"->":"0.85"},null]}],[{"->":".^.b"},{"b":["^ empty",{"->":"0.85"},null]}],"nop","\n","ev",{"list":{"list2.a2":1}},"/ev",{"VAR=":"vlist","re":true},"ev",{"VAR?":"vlist"},"out","/ev","\n","ev",{"VAR?":"vlist"},"LIST_ALL","out","/ev","\n","^range:","ev",{"VAR?":"list2"},1,2,"range","out","/ev","\n","ev",{"VAR?":"list2"},{"VAR?":"a1"},{"VAR?":"a3"},"range","out","/ev","\n","^subtract:","ev",{"list":{"list1.a1":1,"list1.b1":2,"list1.c1":3}},{"list":{"list1.b1":2}},"-","out","/ev","\n","ev",10,"srnd","pop","/ev","\n","^random:","ev",{"VAR?":"t"},"lrnd","out","/ev","\n","^listinc:","ev",{"list":{"list1.a1":1}},1,"+","out","/ev","\n",["done",{"#f":5,"#n":"g-0"}],null],"done",{"global decl":["ev",{"list":{"list1.a1":1}},{"VAR=":"list1"},{"list":{},"origins":["list2"]},{"VAR=":"list2"},{"list":{},"origins":["list3"]},{"VAR=":"list3"},{"list":{}},{"VAR=":"vlist"},"/ev","end",null],"#f":1}],"listDefs":{"list1":{"a1":1,"b1":2,"c1":3},"list2":{"a2":1,"b2":2,"c2":3},"list3":{"a3":1,"b3":2,"c3":3}}}

0 comments on commit 5b2da13

Please sign in to comment.