t27.aiРусский

Expressions

You will learn

Arithmetic operators and comparisons on the lesson constants, and the bool a comparison gives back.

An expression combines names and numbers with operators. With A = 17 and B = 5, A + B is 22, A - B is 12, A * B is 85, A / B is 3 because whole numbers divide without a fraction, and A % B is 2, the remainder. Comparisons give true or false. One limit of the test runner on this site: it does not read a minus sign in front of a number, so write negative values as constants.

Try it

Change B to 4 and predict each of the five results before you run the tests.

Open the interactive lesson →

t27 basics 9: operators on two numbers
t27 basics 9: operators on two numbers ↗

Every arithmetic and comparison operator of a t27 test, applied to 17 and 5 by the lesson spec. Lesson 9 of the t27 basics course.

specs/basics/09_expressions.t27

// SPDX-License-Identifier: Apache-2.0
; t27 basics, lesson 9: Expressions.
; Arithmetic and comparison operators, and what a test can compute with them.

module basics_09_expressions;

pub const A : u8 = 17;
pub const B : u8 = 5;

test arithmetic_on_whole_numbers {
    assert A + B == 22;
    assert A - B == 12;
    assert A * B == 85;
    assert A / B == 3;
    assert A % B == 2;
}

test comparisons_give_true_or_false {
    assert A > B;
    assert B <= A;
    assert A != B;
}

Open the lesson's spec in the player ↗

All lessons