This hands-on session focuses on implementing basic arithmetic operations and utility functions in Move, a language used on the Aptos blockchain. You will complete the protocol::basic module to pass all the provided test cases. This module includes functions for addition, subtraction, multiplication, division, modulus, finding the maximum and minimum of two numbers, and checking if a number is even.
The project includes a test module (protocol::basic_test) with various test cases to validate the correct implementation of each function in protocol::basic.
- Addition (
add): Verifies that the sum of two numbers is correct. - Subtraction (
minus): Checks that the difference between two numbers is correct. - Multiplication (
multiply): Ensures that the product of two numbers is computed correctly. - Division (
div): Validates that the quotient of two numbers is returned correctly. - Division by Zero (
div): Ensures that attempting to divide by zero results in failure. - Modulus (
mod): Checks that the remainder of division is correct. - Modulus by Zero (
mod): Ensures that attempting to compute the remainder with a divisor of zero fails. - Maximum (
max): Confirms that the maximum of two numbers is returned. - Minimum (
min): Verifies that the minimum of two numbers is returned. - Even Check (
is_even): Tests if a number is even.
-
Ensure your Move development environment is set up and the
aptosCLI is installed. -
Navigate to your project directory in the terminal.
-
Run the tests with the following command:
aptos move testThis command will execute the test cases in
protocol::basic_testand display the results.
Your task is to complete the functions in the protocol::basic module so that all the test cases pass. Below are descriptions of each function:
- Addition (
add): A function that returns the sum of twou64integers. - Subtraction (
minus): A function that returns the difference between twou64integers. - Multiplication (
multiply): A function that returns the product of twou64integers. - Division (
div): A function that returns the quotient whenais divided byband should handle division by zero by failing with an appropriate error. - Modulus (
mod): A function that returns the remainder whenais divided byband should fail whenbis zero. - Maximum (
max): A function that returns the larger of twou64integers. - Minimum (
min): A function that returns the smaller of twou64integers. - Even Check (
is_even): A function that checks whether a givenu64integer is even.
- Error Handling: The division and modulus functions should fail with appropriate error codes when dividing by zero.
- Testing Code: The tests in the
tests/folder validate the behavior of each function. Ensure your implementation passes these tests. - Move Language Features: Use Move's built-in operators and conditional logic to implement each function.
For more information on basic Move syntax and operations, refer to the Aptos Move by Example documentation(https://move-developers-dao.gitbook.io/aptos-move-by-example/basic-concepts/operations). This resource provides an overview of basic operations and concepts in Move, which will be helpful for completing this session.
Completing this hands-on session will provide you with practical knowledge of basic arithmetic operations, conditional handling, and test-driven development in Move.