Skip to content
Snippets Groups Projects
Commit 4773b994 authored by dgelessus's avatar dgelessus
Browse files

Show TRUE instead of nothing when an assertion succeeds

parent 421dab0e
No related branches found
No related tags found
No related merge requests found
%% Cell type:code id: tags:
``` prob
:help :assert
```
%% Output
```
:assert PREDICATE
```
Ensure that the predicate is true, and show an error otherwise.
:assert PREDICATE
Ensure that the predicate is true, and show an error otherwise.
%% Cell type:markdown id: tags:
Asserting a true predicate doesn't show anything.
Asserting a true predicate shows $\mathit{TRUE}$.
%% Cell type:code id: tags:
``` prob
:assert 1 = 1
```
%% Output
$\mathit{TRUE}$
TRUE
%% Cell type:code id: tags:
``` prob
:assert TRUE
```
%% Output
$\mathit{TRUE}$
TRUE
%% Cell type:markdown id: tags:
Asserting a predicate doesn't show any solutions.
%% Cell type:code id: tags:
``` prob
:assert x > 1
```
%% Output
$\mathit{TRUE}$
TRUE
%% Cell type:markdown id: tags:
Asserting a false predicate shows an error.
%% Cell type:code id: tags:
``` prob
:assert 0 = 1
```
%% Output
:assert: Assertion is not true: FALSE
%% Cell type:code id: tags:
``` prob
:assert FALSE
```
%% Output
:assert: Assertion is not true: FALSE
%% Cell type:markdown id: tags:
Asserting something that isn't a predicate/boolean shows an error.
%% Cell type:code id: tags:
``` prob
:assert 123
```
%% Output
:assert: Assertion is not true: 123
%% Cell type:code id: tags:
``` prob
:assert {}
```
%% Output
:assert: Assertion is not true: ∅
%% Cell type:markdown id: tags:
Asserting a formula with errors shows an error.
%% Cell type:code id: tags:
``` prob
:assert 123 + {}
```
%% Output
:assert: Error while evaluating assertion: Computation not completed: Type mismatch: Expected INTEGER, but was POW(_A) in '{}'
......
......@@ -14,7 +14,6 @@ import io.github.spencerpark.jupyter.kernel.display.DisplayData;
import io.github.spencerpark.jupyter.kernel.display.mime.MIMEType;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
public final class AssertCommand implements Command {
private final @NotNull AnimationSelector animationSelector;
......@@ -37,10 +36,11 @@ public final class AssertCommand implements Command {
}
@Override
public @Nullable DisplayData run(final @NotNull ProBKernel kernel, final @NotNull String argString) {
public @NotNull DisplayData run(final @NotNull ProBKernel kernel, final @NotNull String argString) {
final AbstractEvalResult result = this.animationSelector.getCurrentTrace().evalCurrent(argString, FormulaExpand.TRUNCATE);
if (result instanceof EvalResult && "TRUE".equals(((EvalResult)result).getValue())) {
return null;
// Use EvalResult.TRUE instead of the real result so that solution variables are not displayed.
return CommandUtils.displayDataForEvalResult(EvalResult.TRUE);
}
final DisplayData displayData;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment