Files
MuditaOS/module-apps/application-calculator/tests/CalculatorUtility_tests.cpp
T
Lucjan BryndzaandLucjan Bryndza bf2609524c [EGD-4075] Use FATFS in the Linux builds (#843)
* [EGD-4075] Use FAT fs in the emulator

Add script for genrate base phone image

* [EGD-4075] Use FreeRTOS-FAT in emulator initial commit

* [EGD-4075] Thread local storage fix

Fixing thread local storage when running on the
Linux platform in the test mode

* [EGD-4075] Improve image generation

Improve image generation script on the linux platform

* [EGD-4075] Fix all test with FAT fs image

Fix all tests with fatfs image

* [EGD-4075] Fix calculator utility test

* [EGD-4075] Image dependencies fix

* Remove uneeded comments

* Missing headers in CR

* [EGD-4075] Fixed whitespaces

Co-authored-by: Lucjan Bryndza <lucjan.bryndza@mudita.com>
2020-10-22 10:34:12 +02:00

106 lines
2.9 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// Copyright (c) 2017-2020, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md
#define CATCH_CONFIG_MAIN
#include <catch2/catch.hpp>
#include "application-calculator/data/CalculatorUtility.hpp"
#include <module-utils/i18/i18.hpp>
#include <cstring>
class vfs vfs;
struct vfs_initializer
{
vfs_initializer()
{
vfs.Init();
}
} vfs_initializer;
TEST_CASE("Calculator utilities")
{
auto calculator = Calculator();
utils::localize.Switch(utils::Lang::En);
SECTION("Addition")
{
auto result = calculator.calculate("5+4+8+6");
REQUIRE(result.value == "23");
REQUIRE(result.equation == "5+4+8+6");
REQUIRE(!result.isError);
}
SECTION("Subtraction")
{
auto result = calculator.calculate("5-4-8-6");
REQUIRE(result.value == "-13");
REQUIRE(result.equation == "5-4-8-6");
REQUIRE(!result.isError);
}
SECTION("Multiplication")
{
auto result = calculator.calculate("5×5");
REQUIRE(result.value == "25");
REQUIRE(result.equation == "5*5");
REQUIRE(!result.isError);
}
SECTION("Division")
{
auto result = calculator.calculate("15÷3");
REQUIRE(result.value == "5");
REQUIRE(result.equation == "15/3");
REQUIRE(!result.isError);
}
SECTION("Mixed operations")
{
auto result = calculator.calculate("15÷3+5×-5-16+40");
REQUIRE(result.value == "4");
REQUIRE(result.equation == "15/3+5*-5-16+40");
REQUIRE(!result.isError);
}
SECTION("Fraction with full stop")
{
auto result = calculator.calculate("15.5+12.056");
REQUIRE(result.value == "27.556");
REQUIRE(result.equation == "15.5+12.056");
REQUIRE(!result.isError);
}
SECTION("Fraction with comma")
{
utils::localize.Switch(utils::Lang::Pl);
auto result = calculator.calculate("15,5+12,056");
REQUIRE(result.value == "27,556");
REQUIRE(result.equation == "15.5+12.056");
REQUIRE(!result.isError);
}
SECTION("Division by 0")
{
auto result = calculator.calculate("15+5÷0");
REQUIRE(result.value == utils::localize.get("app_calculator_error"));
REQUIRE(result.equation == "15+5/0");
REQUIRE(result.isError);
}
SECTION("Division 0 by 0")
{
auto result = calculator.calculate("0÷0");
REQUIRE(result.value == utils::localize.get("app_calculator_error"));
REQUIRE(result.equation == "0/0");
REQUIRE(result.isError);
}
SECTION("Result exceeds maximum number")
{
auto result = calculator.calculate("1.79769e+308×2");
REQUIRE(result.value == utils::localize.get("app_calculator_error"));
REQUIRE(result.equation == "1.79769e+308*2");
REQUIRE(result.isError);
}
}