Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added translation to C++ #31

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 29 additions & 29 deletions cpp/Platform.Incrementers.Tests/IncrementerTests.cpp
Original file line number Diff line number Diff line change
@@ -1,35 +1,35 @@
namespace Platform::Incrementers::Tests
#include <Platform.Incrementers.h>
#include <gtest/gtest.h>

namespace Platform::Incrementers::Tests
{
TEST_CLASS(IncrementerTests)
TEST(IncrementersTests, ParameterlessConstructedSetterTest)
{
public: TEST_METHOD(ParameterlessConstructedSetterTest)
{
Incrementer<std::int32_t> incrementer = Incrementer<std::int32_t>();
Assert::AreEqual(0, incrementer.Result);
}
Incrementer<int> incrementer = Incrementer<int>();
ASSERT_EQ({}, incrementer.Result());
}

public: TEST_METHOD(ConstructedWithDefaultValueSetterTest)
{
Incrementer<std::int32_t> incrementer = Incrementer<std::int32_t>(9UL);
Assert::AreEqual(9UL, incrementer.Result);
}
TEST(IncrementersTests, ConstructedWithDefaultValueSetterTest)
{
Incrementer<int> incrementer = Incrementer<int>(9UL);
ASSERT_EQ(9UL, incrementer.Result());
}

public: TEST_METHOD(MethodsWithBooleanReturnTypeTest)
{
Incrementer<std::int32_t> incrementer = Incrementer<std::int32_t>();
incrementer.Increment();
Assert::AreEqual(1UL, incrementer.Result);
Assert::IsTrue(incrementer.IncrementAndReturnTrue());
Assert::AreEqual(2UL, incrementer.Result);
}
TEST(IncrementersTests, MethodsWithBooleanReturnTypeTest)
{
Incrementer<int> incrementer = Incrementer<int>();
incrementer.Increment();
ASSERT_EQ(1UL, incrementer.Result());
ASSERT_TRUE(incrementer.IncrementAndReturnTrue());
ASSERT_EQ(2UL, incrementer.Result());
}

public: TEST_METHOD(MethodsWithIntegerReturnTypeTest)
{
Incrementer<std::int32_t, std::int32_t> incrementer = Incrementer<std::int32_t, std::int32_t>(1);
incrementer.Increment();
Assert::AreEqual(1UL, incrementer.Result);
Assert::AreEqual(1, incrementer.IncrementAndReturnTrue());
Assert::AreEqual(2UL, incrementer.Result);
}
};
TEST(IncrementersTests, MethodsWithIntegerReturnTypeTest)
{
Incrementer<int, int> incrementer = Incrementer<int, int>(1);
incrementer.Increment();
ASSERT_EQ(1UL, incrementer.Result());
ASSERT_EQ(1, incrementer.IncrementAndReturnTrue());
ASSERT_EQ(2UL, incrementer.Result());
}
}
6 changes: 3 additions & 3 deletions cpp/Platform.Incrementers/IIncrementer.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
namespace Platform::Incrementers
{
class IIncrementer
template<typename _Type, typename TNumber = void>
concept IIncrementer = requires(_Type object, TNumber parameter)
{
public:
virtual void Increment() = 0;
{object.Increment(parameter)} -> std::same_as<TNumber>;
};
}
10 changes: 1 addition & 9 deletions cpp/Platform.Incrementers/IIncrementer[TNumber].h
Original file line number Diff line number Diff line change
@@ -1,9 +1 @@
namespace Platform::Incrementers
{
template <typename ...> class IIncrementer;
template <typename TNumber> class IIncrementer<TNumber>
{
public:
virtual TNumber Increment(TNumber number) = 0;
};
}
//it's no use
22 changes: 16 additions & 6 deletions cpp/Platform.Incrementers/Incrementer.h
Original file line number Diff line number Diff line change
@@ -1,18 +1,28 @@
namespace Platform::Incrementers
{
class Incrementer : public IIncrementer
template<typename...>
class Incrementer;
template<>
class Incrementer<>
{
protected: std::uint64_t _result = 0;
protected:
std::uint64_t _result = 0;

public: std::uint64_t Result()
public:
[[nodiscard]] std::uint64_t Result() const
{
return _result;
}

public: Incrementer(std::uint64_t initialValue) { _result = initialValue; }
explicit Incrementer(std::uint64_t initialValue) : _result(initialValue)
{
}

public: Incrementer() { }
Incrementer() = default;

public: void Increment() { _result++; }
void Increment()
{
_result++;
}
};
}
25 changes: 17 additions & 8 deletions cpp/Platform.Incrementers/Incrementer[TValue, TDecision].h
Original file line number Diff line number Diff line change
@@ -1,23 +1,32 @@
namespace Platform::Incrementers
{
template <typename ...> class Incrementer;
template <typename TValue, typename TDecision> class Incrementer<TValue, TDecision> : public Incrementer<>
template<typename...>
class Incrementer;
template<typename TValue, typename TDecision>
class Incrementer<TValue, TDecision> : public Incrementer<>
{
private: TDecision _trueValue = 0;
private:
using base = Incrementer<>;
const TDecision _trueValue;

public: Incrementer(std::uint64_t initialValue, TDecision trueValue) : Incrementer<>(initialValue) { return _trueValue = trueValue; }
public:
Incrementer(std::uint64_t initialValue, TDecision trueValue) : base(initialValue), _trueValue(trueValue)
{
}

public: Incrementer(TDecision trueValue) { _trueValue = trueValue; }
Incrementer(TDecision trueValue) : _trueValue(trueValue)
{
}

public: Incrementer() { }
Incrementer() = default;

public: TDecision IncrementAndReturnTrue()
TDecision IncrementAndReturnTrue()
{
_result++;
return _trueValue;
}

public: TDecision IncrementAndReturnTrue(TValue value)
TDecision IncrementAndReturnTrue(TValue value)
{
_result++;
return _trueValue;
Expand Down
18 changes: 14 additions & 4 deletions cpp/Platform.Incrementers/Incrementer[TValue].h
Original file line number Diff line number Diff line change
@@ -1,10 +1,20 @@
namespace Platform::Incrementers
{
template <typename ...> class Incrementer;
template <typename TValue> class Incrementer<TValue> : public Incrementer<TValue, bool>
template<typename...>
class Incrementer;
template<typename TValue>
class Incrementer<TValue> : public Incrementer<TValue, bool>
{
public: Incrementer(std::uint64_t initialValue) : Incrementer<TValue, bool>(initialValue, true) { }
private:
using base = Incrementer<TValue, bool>;

public: Incrementer() : Incrementer<TValue, bool>(true) { }
public:
Incrementer(std::uint64_t initialValue) : base(initialValue, true)
{
}

Incrementer() : base(true)
{
}
};
}
13 changes: 13 additions & 0 deletions cpp/Platform.Incrementers/Platform.Incrementers.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#ifndef PLATFORM_INCREMENTERS
#define PLATFORM_INCREMENTERS

#include <concepts>
#include <cstdint>

#include "IIncrementer.h"
#include "IIncrementer[TNumber].h"
#include "Incrementer.h"
#include "Incrementer[TValue, TDecision].h"
#include "Incrementer[TValue].h"

#endif//PLATFORM_INCREMENTERS