-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #96 from NillionNetwork/0.6.0
0.6.0
- Loading branch information
Showing
9 changed files
with
626 additions
and
819 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,11 @@ | ||
import NadaDataTypesTable from '../\_data-types-table.mdx'; | ||
|
||
# Primitive Data Types | ||
# Primitive Modes and Data Types | ||
|
||
This chart shows the primitive data types available in Nada. Each data type links to example Nada programs. | ||
This chart displays the primitive data types available in Nada, categorized by mode. The modes link to Nada program examples for each data type. | ||
|
||
<NadaDataTypesTable/> | ||
|
||
[Secret](/nada-by-example/secret-data-type) and [Public](/nada-by-example/public-data-type) data types are used to specify user inputs to a Nada program. | ||
[Secret](/nada-by-example/secret-data-type) and [Public](/nada-by-example/public-data-type) modes specify whether user inputs to a Nada program are treated as secret (private) or public data. | ||
|
||
[Literals](/nada-by-example/literal-data-type) can only be used within a Nada program. | ||
[Literals](/nada-by-example/literal-data-type) are constants that can only be used within a Nada program and are not tied to specific user inputs. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# Not | ||
|
||
import Tabs from '@theme/Tabs'; | ||
import TabItem from '@theme/TabItem'; | ||
import TestProgram from '@site/src/components/TestProgram/index'; | ||
|
||
The NOT operator, represented by the tilde symbol (~), is used in the Nada DSL to invert or negate a boolean value. When applied to a boolean expression, the ~ operator flips its value—turning True to False and False to True. | ||
|
||
<Tabs> | ||
|
||
<TabItem value="program" label="Nada program" default> | ||
```python reference showGithubLink | ||
https://github.com/NillionNetwork/nada-by-example/blob/main/src/not.py | ||
``` | ||
</TabItem> | ||
|
||
<TabItem value="tie" label="Test 1"> | ||
```yaml reference showGithubLink | ||
https://github.com/NillionNetwork/nada-by-example/blob/main/tests/not_test_1.yaml | ||
``` | ||
</TabItem> | ||
<TabItem value="rock" label="Test 2"> | ||
```yaml reference showGithubLink | ||
https://github.com/NillionNetwork/nada-by-example/blob/main/tests/not_test_2.yaml | ||
``` | ||
</TabItem> | ||
</Tabs> | ||
|
||
<TestProgram programName="not" testFileName="not_test_1"/> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
# Shuffle | ||
|
||
import Tabs from '@theme/Tabs'; | ||
import TabItem from '@theme/TabItem'; | ||
import TestProgram from '@site/src/components/TestProgram/index'; | ||
|
||
|
||
## Simple Shuffle | ||
|
||
This example uses the [nada-numpy](/nada-numpy-introduction) shuffle implementation to shuffle an array of four secret integers and return the shuffled values. This process preserves the original elements but places them in a different order. | ||
|
||
<Tabs> | ||
|
||
<TabItem value="program" label="Nada program" default> | ||
```python reference showGithubLink | ||
https://github.com/NillionNetwork/nada-by-example/blob/main/src/shuffle_simple.py | ||
``` | ||
</TabItem> | ||
|
||
<TabItem value="test" label="Test"> | ||
```yaml reference showGithubLink | ||
https://github.com/NillionNetwork/nada-by-example/blob/main/tests/shuffle_simple_test.yaml | ||
``` | ||
</TabItem> | ||
<TabItem value="nada_test" label="nada-test"> | ||
```python reference showGithubLink | ||
https://github.com/NillionNetwork/nada-by-example/blob/main/tests/shuffle_simple_test.py | ||
``` | ||
</TabItem> | ||
</Tabs> | ||
|
||
<TestProgram programName="shuffle_simple" testFileName="shuffle_simple_test"/> | ||
|
||
## More Shuffle Examples | ||
|
||
This example demonstrates how the [nada-numpy](/nada-numpy-introduction) shuffling operation supports multiple data types, including Rational, SecretRational, PublicInteger, and SecretInteger. Shuffling can be applied using two approaches: the `shuffle()` function or the built-in `.shuffle()` method on arrays. | ||
|
||
<Tabs> | ||
|
||
<TabItem value="program" label="Nada program" default> | ||
```python reference showGithubLink | ||
https://github.com/NillionNetwork/nada-by-example/blob/main/src/shuffle.py | ||
``` | ||
</TabItem> | ||
|
||
<TabItem value="test" label="Test"> | ||
```yaml reference showGithubLink | ||
https://github.com/NillionNetwork/nada-by-example/blob/main/tests/shuffle_test.yaml | ||
``` | ||
</TabItem> | ||
</Tabs> | ||
|
||
<TestProgram programName="shuffle" testFileName="shuffle_test"/> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
import Tabs from '@theme/Tabs'; | ||
import TabItem from '@theme/TabItem'; | ||
|
||
# nada-test: Nada Testing Framework | ||
|
||
[nada-test](https://pypi.org/project/nada-test) is a powerful and flexible testing framework for Nada programs. It enables developers to write dynamic tests that are generated at runtime, offering more flexibility than traditional YAML test files. | ||
|
||
#### Features | ||
|
||
- Dynamic test generation at runtime | ||
- Easy-to-write test functions using Python | ||
- Seamless integration with `nada` projects | ||
- Support for both standalone usage and integration with pytest | ||
- Flexible input and output specification for test cases | ||
|
||
## Installation | ||
|
||
You can install [nada-test](https://pypi.org/project/nada-test) in a Nada project using pip: | ||
|
||
```bash | ||
pip install nada-test | ||
``` | ||
|
||
## Setup | ||
|
||
To use nada-test as your test framework, you’ll need to configure it in your nada-project.toml file. This allows the nada test command to automatically run your tests using the nada-test framework. Here’s how you can set it up: | ||
|
||
<Tabs> | ||
<TabItem value="basic" label="Basic configuration" default> | ||
Add the following to your nada-project.toml file to set nada-test as your default test runner and point it to the ./tests directory: | ||
```toml | ||
[test_framework.nada-test] | ||
command = "nada-test ./tests" | ||
``` | ||
|
||
This setup ensures that all tests inside the ./tests directory will be executed when you run nada test. | ||
</TabItem> | ||
|
||
<TabItem value="custom" label="Custom test directories"> | ||
If you have tests in multiple directories, you can specify them in the configuration as well: | ||
|
||
```toml | ||
[test_framework.nada-test] | ||
command = "nada-test ./custom_tests ./more_tests" | ||
``` | ||
|
||
This allows you to organize your tests across different directories, and nada test will run all tests from the specified paths. | ||
</TabItem> | ||
</Tabs> | ||
|
||
|
||
## Writing tests | ||
|
||
You can use nada-test to write both functional and class-based tests for your programs. Tests are decorated with `@nada_test(program="program_name")` to specify which program is being tested. Below are two examples showing how to test a basic addition program. | ||
|
||
Tests should be written in a Python file located in the directory you specified during the setup (e.g., ./tests or any custom test directory). Below are examples of how to test a basic addition program using both styles. | ||
|
||
### Functional style test | ||
|
||
<Tabs> | ||
<TabItem value="test" label="nada-test file" default> | ||
```python reference showGithubLink | ||
https://github.com/NillionNetwork/nada-by-example/blob/main/tests/addition_test.py#L4-L11 | ||
``` | ||
</TabItem> | ||
|
||
<TabItem value="program" label="Nada program"> | ||
```python reference showGithubLink | ||
https://github.com/NillionNetwork/nada-by-example/blob/main/src/addition.py | ||
``` | ||
</TabItem> | ||
</Tabs> | ||
|
||
### Class-based test | ||
|
||
|
||
<Tabs> | ||
<TabItem value="test" label="nada-test file" default> | ||
```python reference showGithubLink | ||
https://github.com/NillionNetwork/nada-by-example/blob/main/tests/addition_test.py#L13-L21 | ||
``` | ||
</TabItem> | ||
|
||
<TabItem value="program" label="Nada program"> | ||
```python reference showGithubLink | ||
https://github.com/NillionNetwork/nada-by-example/blob/main/src/addition.py | ||
``` | ||
</TabItem> | ||
</Tabs> | ||
|
||
|
||
## Running tests | ||
|
||
After writing your tests in the specified directories, you can run them using the following command: | ||
|
||
``` | ||
nada test | ||
``` | ||
|
||
This will execute all the tests configured in your nada-project.toml file. The output will show you the results of your test suite. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,168 @@ | ||
module.exports = [ | ||
{ | ||
type: 'html', | ||
className: 'sidebar-title', | ||
value: 'Nada by Example', | ||
defaultStyle: true, | ||
}, | ||
{ | ||
type: 'doc', | ||
label: 'Introduction', | ||
id: 'nada-by-example', | ||
}, | ||
'nada-by-example/first-program', | ||
{ | ||
type: 'doc', | ||
label: 'How to Run Examples', | ||
id: 'nada-by-example-quickstart', | ||
}, | ||
'nada-by-example/debugging', | ||
{ | ||
type: 'link', | ||
label: 'Ask a Nada Question', | ||
href: 'https://github.com/orgs/NillionNetwork/discussions/categories/q-a', | ||
}, | ||
{ | ||
type: 'html', | ||
className: 'sidebar-title', | ||
value: 'Nada Program Examples', | ||
defaultStyle: true, | ||
}, | ||
{ | ||
type: 'category', | ||
label: 'Primitive Data Types', | ||
link: { | ||
type: 'doc', | ||
id: 'nada-by-example/nada-data-types', | ||
}, | ||
items: [ | ||
'nada-by-example/secret-data-type', | ||
'nada-by-example/public-data-type', | ||
'nada-by-example/literal-data-type', | ||
], | ||
}, | ||
{ | ||
type: 'category', | ||
label: 'Nada Operations', | ||
link: { | ||
type: 'doc', | ||
id: 'nada-by-example/nada-operations', | ||
}, | ||
items: [ | ||
'nada-by-example/addition', | ||
'nada-by-example/subtraction', | ||
'nada-by-example/multiplication', | ||
'nada-by-example/division', | ||
'nada-by-example/power', | ||
'nada-by-example/modulo', | ||
'nada-by-example/shift-left', | ||
'nada-by-example/shift-right', | ||
'nada-by-example/probabilistic-truncation', | ||
'nada-by-example/comparison', | ||
'nada-by-example/equality', | ||
'nada-by-example/not', | ||
'nada-by-example/if-else', | ||
'nada-by-example/reveal', | ||
], | ||
}, | ||
'nada-by-example/list-comprehensions', | ||
'nada-by-example/for-loop', | ||
'nada-by-example/helper-function', | ||
'nada-by-example/reduce', | ||
'nada-by-example/random-number', | ||
'nada-by-example/linear-scan', | ||
'nada-by-example/shuffle', | ||
'nada-by-example/square-root', | ||
'nada-by-example/cube-root', | ||
'nada-by-example/arg-max', | ||
'nada-by-example/variance', | ||
'nada-by-example/standard-deviation', | ||
'nada-by-example/cardio-risk', | ||
'nada-by-example/voting', | ||
'nada-by-example/r-p-s', | ||
{ | ||
type: 'link', | ||
label: 'Request an Example', | ||
href: 'https://github.com/nillionnetwork/nada-by-example/issues/new/choose', | ||
}, | ||
{ | ||
type: 'html', | ||
className: 'sidebar-title', | ||
value: 'Examples with Nada Libraries', | ||
defaultStyle: true, | ||
}, | ||
{ | ||
type: 'category', | ||
label: 'Nada AI', | ||
collapsible: true, | ||
collapsed: false, | ||
link: { | ||
type: 'doc', | ||
id: 'nada-by-example/nada-ai', | ||
}, | ||
items: [ | ||
{ | ||
type: 'link', | ||
label: 'Linear Regression', | ||
href: 'https://github.com/NillionNetwork/nada-ai/tree/main/examples/linear_regression', | ||
}, | ||
{ | ||
type: 'link', | ||
label: 'Neural Network', | ||
href: 'https://github.com/NillionNetwork/nada-ai/tree/main/examples/neural_net', | ||
}, | ||
{ | ||
type: 'link', | ||
label: 'Complex Model', | ||
href: 'https://github.com/NillionNetwork/nada-ai/tree/main/examples/complex_model', | ||
}, | ||
{ | ||
type: 'link', | ||
label: 'Time Series', | ||
href: 'https://github.com/NillionNetwork/nada-ai/tree/main/examples/time_series', | ||
}, | ||
{ | ||
type: 'link', | ||
label: 'Spam Detection', | ||
href: 'https://github.com/NillionNetwork/nada-ai/tree/main/examples/spam_detection', | ||
}, | ||
{ | ||
type: 'link', | ||
label: 'Convolutional Neural Network', | ||
href: 'https://github.com/NillionNetwork/nada-ai/tree/main/examples/conv_net', | ||
}, | ||
], | ||
}, | ||
{ | ||
type: 'category', | ||
label: 'Nada Numpy', | ||
collapsible: true, | ||
collapsed: false, | ||
link: { | ||
type: 'doc', | ||
id: 'nada-by-example/nada-numpy', | ||
}, | ||
items: [ | ||
{ | ||
type: 'link', | ||
label: 'Dot Product', | ||
href: 'https://github.com/NillionNetwork/nada-numpy/tree/main/examples/dot_product', | ||
}, | ||
{ | ||
type: 'link', | ||
label: 'Matrix Multiplication', | ||
href: 'https://github.com/NillionNetwork/nada-numpy/tree/main/examples/matrix_multiplication', | ||
}, | ||
{ | ||
type: 'link', | ||
label: 'Broadcasting', | ||
href: 'https://github.com/NillionNetwork/nada-numpy/tree/main/examples/broadcasting', | ||
}, | ||
{ | ||
type: 'link', | ||
label: 'Rational Numbers', | ||
href: 'https://github.com/NillionNetwork/nada-numpy/tree/main/examples/rational_numbers', | ||
}, | ||
], | ||
}, | ||
]; |
Oops, something went wrong.