Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
ProB 2 Jupyter Kernel
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Requirements
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
general
stups
ProB 2 Jupyter Kernel
Commits
4773b994
Commit
4773b994
authored
7 years ago
by
dgelessus
Browse files
Options
Downloads
Patches
Plain Diff
Show TRUE instead of nothing when an assertion succeeds
parent
421dab0e
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
notebooks/tests/assert.ipynb
+66
-8
66 additions, 8 deletions
notebooks/tests/assert.ipynb
src/main/java/de/prob2/jupyter/commands/AssertCommand.java
+3
-3
3 additions, 3 deletions
src/main/java/de/prob2/jupyter/commands/AssertCommand.java
with
69 additions
and
11 deletions
notebooks/tests/assert.ipynb
+
66
−
8
View file @
4773b994
...
...
@@ -33,14 +33,28 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"Asserting a true predicate
doesn't show anything
."
"Asserting a true predicate
shows $\\mathit{TRUE}$
."
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"text/markdown": [
"$\\mathit{TRUE}$"
],
"text/plain": [
"TRUE"
]
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
":assert 1 = 1"
]
...
...
@@ -49,7 +63,21 @@
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"text/markdown": [
"$\\mathit{TRUE}$"
],
"text/plain": [
"TRUE"
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
":assert TRUE"
]
...
...
@@ -58,13 +86,43 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"Asserting a
false
predicate show
s
an
error
."
"Asserting a predicate
doesn't
show an
y solutions
."
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"data": {
"text/markdown": [
"$\\mathit{TRUE}$"
],
"text/plain": [
"TRUE"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
":assert x > 1"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Asserting a false predicate shows an error."
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [
{
"ename": "CommandExecutionException",
...
...
@@ -81,7 +139,7 @@
},
{
"cell_type": "code",
"execution_count":
5
,
"execution_count":
6
,
"metadata": {},
"outputs": [
{
...
...
@@ -106,7 +164,7 @@
},
{
"cell_type": "code",
"execution_count":
6
,
"execution_count":
7
,
"metadata": {},
"outputs": [
{
...
...
@@ -124,7 +182,7 @@
},
{
"cell_type": "code",
"execution_count":
7
,
"execution_count":
8
,
"metadata": {},
"outputs": [
{
...
...
@@ -149,7 +207,7 @@
},
{
"cell_type": "code",
"execution_count":
8
,
"execution_count":
9
,
"metadata": {},
"outputs": [
{
...
...
%% 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 $
\m
athit{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 '{}'
...
...
This diff is collapsed.
Click to expand it.
src/main/java/de/prob2/jupyter/commands/AssertCommand.java
+
3
−
3
View file @
4773b994
...
...
@@ -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
@Null
able
DisplayData
run
(
final
@NotNull
ProBKernel
kernel
,
final
@NotNull
String
argString
)
{
public
@N
otN
ull
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
;
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment