Skip to content

Commit

Permalink
Progress on #28, some reportings in tests decent
Browse files Browse the repository at this point in the history
  • Loading branch information
oggy22 committed Jul 17, 2017
1 parent 1da8db1 commit 62b1c49
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 6 deletions.
1 change: 1 addition & 0 deletions TestTranslatorCpp/TestTranslatorCpp.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@
<ClInclude Include="MockLanguage.h" />
<ClInclude Include="stdafx.h" />
<ClInclude Include="targetver.h" />
<ClInclude Include="wstring_outputs.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="attribute_manager_test.cpp" />
Expand Down
18 changes: 17 additions & 1 deletion TestTranslatorCpp/english_test.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
#include "stdafx.h"
#include "../TranslatorCpp/Languages/English.h"
std::wostream& operator<<(std::wostream&wout, English::word_type wt)
{
switch (wt)
{
case noun: wout << L"noun"; break;
case verb: wout << L"verb"; break;
default: FAIL("Unknown English::word_type");
}
return wout;
}
#include "wstring_outputs.h"

using namespace Microsoft::VisualStudio::CppUnitTestFramework;
std::ofstream test_output("english_test.log");
Expand All @@ -19,7 +30,12 @@ namespace TranslatorTest
{
for (auto& rule : English::word_rules)
{
Assert::IsTrue(rule.used/*, (std::wstring)(rule.destination)*/);
if (!rule.used)
{
std::wstringstream wss;
wss << rule << L" not used";
Assert::Fail(wss.str().c_str());
}
}
}
#endif
Expand Down
26 changes: 23 additions & 3 deletions TestTranslatorCpp/serbian_test.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
#include "stdafx.h"
#include "../TranslatorCpp/Languages/Serbian.h"
std::wostream& operator<<(std::wostream&wout, Serbian::word_type wt)
{
switch (wt)
{
case Serbian::word_type::именица: wout << L"именица"; break;
case Serbian::word_type::глагол: wout << L"глагол"; break;
case Serbian::word_type::придев: wout << L"придев"; break;
default: FAIL("Unknown Serbian::word_type");
}
return wout;
}

#include "wstring_outputs.h"

using namespace Microsoft::VisualStudio::CppUnitTestFramework;
std::wofstream test_output("serbian_test.log");
Expand All @@ -26,7 +39,12 @@ namespace TranslatorTest
{
for (auto& rule : Serbian::word_rules)
{
Assert::IsTrue(rule.used/*, (std::wstring)(rule.destination)*/);
if (!rule.used)
{
std::wstringstream wss;
wss << rule << L" not used";
Assert::Fail(wss.str().c_str());
}
}
}
#endif
Expand All @@ -36,12 +54,14 @@ namespace TranslatorTest
for (const auto& word : Serbian::dictWords())
{
for (wchar_t c : word.word)
Assert::AreNotEqual(std::wstring::npos, Serbian::stAlphabet.find(c));
Assert::AreNotEqual(std::wstring::npos, Serbian::stAlphabet.find(c),
word.word.c_str());

for (const auto& w : word.words)
{
for (wchar_t c : w.word)
Assert::AreNotEqual(std::wstring::npos, Serbian::stAlphabet.find(c));
Assert::AreNotEqual(std::wstring::npos, Serbian::stAlphabet.find(c),
w.word.c_str());
}
}
}
Expand Down
14 changes: 14 additions & 0 deletions TestTranslatorCpp/wstring_outputs.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#pragma once
template <class Char>
std::wostream& operator<<(std::wostream &wout, const translator::pattern<Char>& pt)
{
pt.printw(wout);
return wout;
}

template <class Language>
std::wostream& operator<<(std::wostream &wout, const translator::word_rule<Language>& wr)
{
wout << L"'" << wr.source << L"'->'" << wr.destination << L"' " << wr.wt;
return wout;
}
2 changes: 0 additions & 2 deletions TranslatorCpp/language.h
Original file line number Diff line number Diff line change
Expand Up @@ -313,8 +313,6 @@ namespace translator
populate_words<Lang>();
initialized = true;
#ifdef _DEBUG
for (auto& rule : word_rules)
ASSERT(rule.used);
for (auto& rule : word_to_word_rules)
ASSERT(rule.used);
#endif
Expand Down
7 changes: 7 additions & 0 deletions TranslatorCpp/pattern.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,5 +100,12 @@ namespace translator

return to.pre + input.substr(pre.length(), core_len) + to.post;
}

void printw(std::wostream& wos) const
{
wos << std::wstring(pre.begin(), pre.end());
if (has_joker)
wos << L"*" << std::wstring(post.begin(), post.end());
}
};
}

0 comments on commit 62b1c49

Please sign in to comment.