Skip to content

Commit

Permalink
a
Browse files Browse the repository at this point in the history
  • Loading branch information
fintarin committed Feb 19, 2024
1 parent 00b4f65 commit ba86ae8
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 14 deletions.
2 changes: 2 additions & 0 deletions include/fintamath/core/MathObjectBoundTypes.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#pragma once

#include <cstddef>
#include <unordered_map>
#include <utility>

#include "fintamath/core/MathObjectType.hpp"

Expand Down
4 changes: 2 additions & 2 deletions include/fintamath/exceptions/Exception.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

#include <exception>
#include <string>
#include <string_view>
#include <utility>

namespace fintamath {

class Exception : public std::exception {
public:
explicit Exception(const std::string_view inMessage) : message(inMessage) {
explicit Exception(std::string inMessage) : message(std::move(inMessage)) {
}

const char *what() const noexcept override {
Expand Down
4 changes: 2 additions & 2 deletions include/fintamath/exceptions/InvalidInputException.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@

#include <cstdint>
#include <string>
#include <string_view>
#include <utility>

#include "fintamath/exceptions/Exception.hpp"

namespace fintamath {

class InvalidInputException : public Exception {
public:
explicit InvalidInputException(const std::string_view inMessage) : Exception(inMessage) {
explicit InvalidInputException(std::string inMessage) : Exception(std::move(inMessage)) {
}
};

Expand Down
4 changes: 2 additions & 2 deletions include/fintamath/exceptions/UndefinedException.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@

#include <cstdint>
#include <string>
#include <string_view>
#include <utility>

#include "fintamath/exceptions/Exception.hpp"

namespace fintamath {

class UndefinedException : public Exception {
public:
explicit UndefinedException(const std::string_view inMessage) : Exception(inMessage) {
explicit UndefinedException(std::string inMessage) : Exception(std::move(inMessage)) {
}
};

Expand Down
6 changes: 3 additions & 3 deletions src/fintamath/literals/Variable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ namespace fintamath {
Variable::Variable(const std::string_view inName) {
if (inName.size() != 1) {
throw InvalidInputException(
fmt::format(R"(Invalid {} "{}" (name expected to be 1 character))", getTypeStatic().getName(), inName));
fmt::format(R"(Invalid {} name "{}" (expected a 1 character))", getTypeStatic().getName(), inName));
}

if (const char ch = inName.front(); ch < 'a' || ch > 'z') {
throw InvalidInputException(
fmt::format(R"(Invalid {} "{}" (name expected to be an English lowercase letter))", getTypeStatic().getName(), inName));
fmt::format(R"(Invalid {} name "{}" (expected an English lowercase letter))", getTypeStatic().getName(), inName));
}

name = std::string(inName);
Expand All @@ -28,7 +28,7 @@ Variable::Variable(const std::string_view inName) {
Variable::Variable(const std::string_view inName, Integer inIndex) : Variable(inName) {
if (inIndex < 0) {
throw InvalidInputException(
fmt::format(R"(Invalid {} "{}_{}" (expected index >= 0))", getTypeStatic().getName(), name, inIndex.toString()));
fmt::format(R"(Invalid {} index "{}" (expected >= 0))", getTypeStatic().getName(), inIndex.toString()));
}

index = std::move(inIndex);
Expand Down
2 changes: 1 addition & 1 deletion src/fintamath/numbers/Real.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ void Real::updatePrecision(const Real &rhs) {

void Real::validateNewPrecision(const unsigned precision) const {
if (precision > outputPrecision) {
throw InvalidInputException(fmt::format("Invalid precision {} (expected precision <= {})", precision, outputPrecision));
throw InvalidInputException(fmt::format("Invalid precision {} (expected <= {})", precision, outputPrecision));
}
}

Expand Down
8 changes: 4 additions & 4 deletions tests/src/literals/VariableTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,14 +82,14 @@ TEST(VariableTest, stringIntegerConstructorTest) {
testing::ThrowsMessage<InvalidInputException>(
testing::StrEq(R"(Invalid Variable "|" (name expected to be an English lowercase letter))")));

EXPECT_THAT(
[] { Variable("A", 1); },
testing::ThrowsMessage<InvalidInputException>(
testing::StrEq(R"(Invalid Variable "A" (name expected to be an English lowercase letter))")));
EXPECT_THAT(
[] { Variable("ab", 1); },
testing::ThrowsMessage<InvalidInputException>(
testing::StrEq(R"(Invalid Variable "ab" (name expected to be 1 character))")));
EXPECT_THAT(
[] { Variable("A", 1); },
testing::ThrowsMessage<InvalidInputException>(
testing::StrEq(R"(Invalid Variable "A" (name expected to be an English lowercase letter))")));
EXPECT_THAT(
[] { Variable("a", -1); },
testing::ThrowsMessage<InvalidInputException>(
Expand Down

0 comments on commit ba86ae8

Please sign in to comment.