Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tests for seq #2840

Merged
merged 9 commits into from
Apr 12, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions eo-runtime/src/test/eo/org/eolang/seq-tests.eo
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,28 @@
counter.as-int.plus 1
counter.as-int
1

# Test.
[] > seq-single-dataization-int-equal-to-test
memory 0 > x
eq. > @
seq
*
x.write 0
x.write (x.as-int.plus 1)
x.as-int
1

# Test.
[] > seq-single-dataization-int-equal-to-test-bug
memory 0 > x
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@c71n93 @yegor256 some changes are required. (memory 0).alloc should be here

eq. > nop
seq
*
at.
* 0 1
x.as-int
x.write (x.as-int.plus 1)
x.as-int
1
TRUE > @
122 changes: 122 additions & 0 deletions eo-runtime/src/test/java/EOorg/EOeolang/EOseqTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,13 @@

import org.eolang.Data;
import org.eolang.Dataized;
import org.eolang.PhCopy;
import org.eolang.PhMethod;
import org.eolang.PhWith;
import org.eolang.Phi;
import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;

/**
Expand Down Expand Up @@ -81,4 +84,123 @@ public void calculatesAndReturnsObject() {
Matchers.startsWith("Hello")
);
}

/**
* Test.
*
* [] > parent
* memory 0 > counter
* seq > @
* *
* at.
* * 0 1
* counter.as-int
* counter.write (counter.as-int.plus 1)
* counter.as-int
*
* @since 1.0
*/
@Disabled
@Test
public void calculatesWithTupleAndReturnsObject() {
final Phi counter = new EOmemory(Phi.Φ);
counter.attr(0).put(new Data.ToPhi(0L));
final Phi arr = new PhWith(
new PhWith(
new EOtuple$EOempty(Phi.Φ).attr("with").get().copy(),
0, new Data.ToPhi(0L)
).attr("with").get().copy(),
0, new Data.ToPhi(1L)
);
final Phi get = new PhWith(
new PhCopy(new PhMethod(arr, "at")),
0, new PhMethod(counter, "as-int")
);
final Phi increment = new PhWith(
new PhCopy(new PhMethod(counter, "write")),
0,
new PhWith(
new PhCopy(new PhMethod(new PhMethod(counter, "as-int"), "plus")),
0, new Data.ToPhi(1L)
)
);
final Phi args = new PhWith(
new PhCopy(
new PhMethod(
new PhWith(
new PhCopy(
new PhMethod(
new PhWith(
new PhCopy(
new PhMethod(new EOtuple$EOempty(Phi.Φ), "with")
),
0,
get
),
"with"
)
),
0,
increment
),
"with"
)
),
0, new PhMethod(counter, "as-int")
);
MatcherAssert.assertThat(
new Dataized(
new PhWith(new EOseq(Phi.Φ), 0, args)
).take(Long.class),
Matchers.equalTo(1L)
);
}

/**
* Test.
*
* [] > parent
* memory 0 > counter
* seq > @
* *
* counter.write (counter.as-int.plus 1)
* counter.as-int
*
* @since 1.0
*/
@Disabled
@Test
public void calculatesWithoutTupleAndReturnsObject() {
final Phi counter = new EOmemory(Phi.Φ);
counter.attr(0).put(new Data.ToPhi(0L));
final Phi increment = new PhWith(
new PhCopy(new PhMethod(counter, "write")),
0,
new PhWith(
new PhCopy(new PhMethod(new PhMethod(counter, "as-int"), "plus")),
0, new Data.ToPhi(1L)
)
);
final Phi args = new PhWith(
new PhCopy(
new PhMethod(
new PhWith(
new PhCopy(
new PhMethod(new EOtuple$EOempty(Phi.Φ), "with")
),
0,
increment
),
"with"
)
),
0, new PhMethod(counter, "as-int")
);
MatcherAssert.assertThat(
new Dataized(
new PhWith(new EOseq(Phi.Φ), 0, args)
).take(Long.class),
Matchers.equalTo(1L)
);
}
}
Loading