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 item possession in goal criteria #859

Merged
merged 2 commits into from
Nov 14, 2022
Merged

Conversation

kostmo
Copy link
Member

@kostmo kostmo commented Nov 12, 2022

Towards #858

condition: |-
as base {
itemCount <- count "tree";
return $ itemCount > 0;
Copy link
Member Author

Choose a reason for hiding this comment

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

This does not succeed even after grab-bing the tree.

Copy link
Member

Choose a reason for hiding this comment

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

I've been poking at this a bit. Curiously, I've found that it does work correctly if the test is wrapped in a try block, like this:

      as base {
        try {
          itemCount <- count "tree";
          return $ itemCount > 0
        } { return false };
      };

In theory this should not make a difference.

Copy link
Member

Choose a reason for hiding this comment

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

The runtime code for has and count is almost identical. The one big difference between them which seems like it might be relevant is that has does not require any capabilities to use, whereas count requires a counter. But in theory the condition checking robot should be able to use count whether base has a counter or not (and indeed, if I add a counter installed on base it does not change anything).

Copy link
Member

Choose a reason for hiding this comment

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

Hmm, maybe base can not count or something?

Copy link
Member

Choose a reason for hiding this comment

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

I really want to figure out what exceptions are being thrown but I'm not sure how to export that information. @xsebek, any ideas?

Copy link
Member

Choose a reason for hiding this comment

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

@byorgey I just checked by printing exceptions from the hypothetical check and there are none.

I just added this:

sendIO $ putStr "ERROR: "
sendIO $ print m

here:

-- Log exceptions in the message queue so we can check for them in tests
Left exn -> do
em <- use entityMap
time <- use ticks
let h = hypotheticalRobot (Out VUnit emptyStore []) 0
hid = view robotID h
hn = view robotName h
farAway = V2 maxBound maxBound
let m = LogEntry time ErrorTrace hn hid farAway $ formatExn em exn
emitMessage m

Weirdly this is also a transformation that fixes the condition:

t <- time;
if (t < 0) {return true} {
    as base {
        itemCount <- count "tree";
        return $ itemCount > 0;
    };
}

Copy link
Member

Choose a reason for hiding this comment

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

Looking at debug logs (see the debug branch), the count is correct:
image

@kostmo kostmo marked this pull request as ready for review November 14, 2022 04:22
@kostmo kostmo added the merge me Trigger the merge process of the Pull request. label Nov 14, 2022
@mergify mergify bot merged commit cfb8a7c into main Nov 14, 2022
@mergify mergify bot deleted the counting-testcase branch November 14, 2022 06:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merge me Trigger the merge process of the Pull request.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants