Use initializer lists in some places

This commit is contained in:
Thomas Goyne 2013-12-11 15:11:06 -08:00
parent a84e463a06
commit d6a5d9c458
24 changed files with 96 additions and 133 deletions

View file

@ -243,11 +243,8 @@ void Reader::MatchString(std::string& string, InputStream& inputStream) {
}
void Reader::MatchNumber(std::string& sNumber, InputStream& inputStream) {
const char sNumericChars[] = "0123456789.eE-+";
std::set<char> numericChars;
numericChars.insert(sNumericChars, sNumericChars + sizeof(sNumericChars));
while (!inputStream.EOS()&& numericChars.count(inputStream.Peek()))
const char numericChars[] = "0123456789.eE-+";
while (!inputStream.EOS() && std::find(numericChars, std::end(numericChars), inputStream.Peek()) != std::end(numericChars))
sNumber.push_back(inputStream.Get());
}

View file

@ -186,6 +186,13 @@ Framerate::Framerate(std::vector<int> timecodes)
SetFromTimecodes();
}
Framerate::Framerate(std::initializer_list<int> timecodes)
: timecodes(timecodes)
, drop(false)
{
SetFromTimecodes();
}
void Framerate::swap(Framerate &right) throw() {
using std::swap;
swap(numerator, right.numerator);

View file

@ -108,6 +108,7 @@ public:
/// @brief VFR from frame times
/// @param timecodes Vector of frame start times in milliseconds
Framerate(std::vector<int> timecodes);
Framerate(std::initializer_list<int> timecodes);
/// Helper function for the std::swap specialization
void swap(Framerate &right) throw();

View file

@ -590,24 +590,24 @@ void AudioTimingControllerDialogue::Revert()
void AudioTimingControllerDialogue::AddLeadIn()
{
DialogueTimingMarker *m = active_line.GetLeftMarker();
SetMarkers(std::vector<AudioMarker*>(1, m), *m - OPT_GET("Audio/Lead/IN")->GetInt());
SetMarkers({ m }, *m - OPT_GET("Audio/Lead/IN")->GetInt());
}
void AudioTimingControllerDialogue::AddLeadOut()
{
DialogueTimingMarker *m = active_line.GetRightMarker();
SetMarkers(std::vector<AudioMarker*>(1, m), *m + OPT_GET("Audio/Lead/OUT")->GetInt());
SetMarkers({ m }, *m + OPT_GET("Audio/Lead/OUT")->GetInt());
}
void AudioTimingControllerDialogue::ModifyLength(int delta, bool) {
DialogueTimingMarker *m = active_line.GetRightMarker();
SetMarkers(std::vector<AudioMarker*>(1, m),
SetMarkers({ m },
std::max<int>(*m + delta * 10, *active_line.GetLeftMarker()));
}
void AudioTimingControllerDialogue::ModifyStart(int delta) {
DialogueTimingMarker *m = active_line.GetLeftMarker();
SetMarkers(std::vector<AudioMarker*>(1, m),
SetMarkers({ m },
std::min<int>(*m + delta * 10, *active_line.GetRightMarker()));
}

View file

@ -375,7 +375,7 @@ std::vector<AudioMarker*> AudioTimingControllerKaraoke::OnLeftClick(int ms, bool
AnnounceUpdatedPrimaryRange();
AnnounceUpdatedStyleRanges();
return std::vector<AudioMarker*>();
return {};
}
std::vector<AudioMarker*> AudioTimingControllerKaraoke::OnRightClick(int ms, bool, int, int) {
@ -385,7 +385,7 @@ std::vector<AudioMarker*> AudioTimingControllerKaraoke::OnRightClick(int ms, boo
AnnounceUpdatedStyleRanges();
c->audioController->PlayPrimaryRange();
return std::vector<AudioMarker*>();
return {};
}
int AudioTimingControllerKaraoke::MoveMarker(KaraokeMarker *marker, int new_position) {

View file

@ -293,8 +293,8 @@ namespace Automation4 {
std::string GetVersion() const override { return ""; }
bool GetLoadedState() const override { return false; }
std::vector<cmd::Command*> GetMacros() const override { return std::vector<cmd::Command*>(); }
std::vector<ExportFilter*> GetFilters() const override { return std::vector<ExportFilter*>(); }
std::vector<SubtitleFormat*> GetFormats() const override { return std::vector<SubtitleFormat*>(); }
std::vector<cmd::Command*> GetMacros() const override { return {}; }
std::vector<ExportFilter*> GetFilters() const override { return {}; }
std::vector<SubtitleFormat*> GetFormats() const override { return {}; }
};
}

View file

@ -338,7 +338,7 @@ namespace Automation4 {
std::vector<cmd::Command*> GetMacros() const override { return macros; }
std::vector<ExportFilter*> GetFilters() const override;
std::vector<SubtitleFormat*> GetFormats() const override { return std::vector<SubtitleFormat*>(); }
std::vector<SubtitleFormat*> GetFormats() const override { return {}; }
};
LuaScript::LuaScript(agi::fs::path const& filename)

View file

@ -330,11 +330,8 @@ void BaseGrid::UpdateMaps(bool preserve_selected_rows) {
SetActiveLine(index_line_map.back());
}
if (selection.empty() && active_line) {
Selection sel;
sel.insert(active_line);
SetSelectedSet(sel);
}
if (selection.empty() && active_line)
SetSelectedSet({ active_line });
EndBatch();
@ -717,9 +714,8 @@ void BaseGrid::OnMouseEvent(wxMouseEvent &event) {
// Toggle each
Selection newsel;
if (ctrl) newsel = selection;
for (int i = i1; i <= i2; i++) {
for (int i = i1; i <= i2; i++)
newsel.insert(GetDialogue(i));
}
SetSelectedSet(newsel);
return;
}
@ -1061,22 +1057,14 @@ void BaseGrid::SetSelectionAndActive(Selection const& new_selection, AssDialogue
void BaseGrid::PrevLine() {
int cur_line_i = GetDialogueIndex(GetActiveLine());
if (AssDialogue *prev_line = GetDialogue(cur_line_i-1)) {
SetActiveLine(prev_line);
Selection newsel;
newsel.insert(prev_line);
SetSelectedSet(newsel);
}
if (AssDialogue *prev_line = GetDialogue(cur_line_i-1))
SetSelectionAndActive({ prev_line }, prev_line);
}
void BaseGrid::NextLine() {
int cur_line_i = GetDialogueIndex(GetActiveLine());
if (AssDialogue *next_line = GetDialogue(cur_line_i+1)) {
SetActiveLine(next_line);
Selection newsel;
newsel.insert(next_line);
SetSelectedSet(newsel);
}
if (AssDialogue *next_line = GetDialogue(cur_line_i+1))
SetSelectionAndActive({ next_line }, next_line);
}
void BaseGrid::AnnounceActiveLineChanged(AssDialogue *new_line) {

View file

@ -525,10 +525,7 @@ static void delete_lines(agi::Context *c, wxString const& commit_message) {
}
c->ass->Commit(commit_message, AssFile::COMMIT_DIAG_ADDREM);
sel.clear();
sel.insert(new_active);
c->selectionController->SetSelectionAndActive(sel, new_active);
c->selectionController->SetSelectionAndActive({ new_active }, new_active);
}
struct edit_line_copy : public validate_sel_nonempty {

View file

@ -125,9 +125,7 @@ static void insert_subtitle_at_video(agi::Context *c, bool after) {
c->ass->Line.insert(pos, *def);
c->ass->Commit(_("line insertion"), AssFile::COMMIT_DIAG_ADDREM);
SubtitleSelection sel;
sel.insert(def);
c->selectionController->SetSelectionAndActive(sel, def);
c->selectionController->SetSelectionAndActive({ def }, def);
}
struct subtitle_insert_after : public validate_nonempty_selection {
@ -160,9 +158,7 @@ struct subtitle_insert_after : public validate_nonempty_selection {
}
c->ass->Commit(_("line insertion"), AssFile::COMMIT_DIAG_ADDREM);
SubtitleSelection sel;
sel.insert(new_line);
c->selectionController->SetSelectionAndActive(sel, new_line);
c->selectionController->SetSelectionAndActive({ new_line }, new_line);
}
};
@ -204,9 +200,7 @@ struct subtitle_insert_before : public validate_nonempty_selection {
}
c->ass->Commit(_("line insertion"), AssFile::COMMIT_DIAG_ADDREM);
SubtitleSelection sel;
sel.insert(new_line);
c->selectionController->SetSelectionAndActive(sel, new_line);
c->selectionController->SetSelectionAndActive({ new_line }, new_line);
}
};

View file

@ -277,9 +277,7 @@ bool DialogSpellChecker::CheckLine(AssDialogue *active_line, int start_pos, int
replace_word->Remove(0, -1);
#endif
SubtitleSelection sel;
sel.insert(active_line);
context->selectionController->SetSelectionAndActive(sel, active_line);
context->selectionController->SetSelectionAndActive({ active_line }, active_line);
SetWord(word);
return true;
}

View file

@ -184,7 +184,7 @@ DEFINE_SIMPLE_EXCEPTION_NOINNER(VersionCheckError, agi::Exception, "versioncheck
void PostErrorEvent(bool interactive, wxString const& error_text) {
if (interactive) {
agi::dispatch::Main().Async([=]{
new VersionCheckerResultDialog(error_text, std::vector<AegisubUpdateDescription>());
new VersionCheckerResultDialog(error_text, {});
});
}
}

View file

@ -79,7 +79,7 @@ public:
}
template<class T>
static void Register(std::string name, bool hide = false, std::vector<std::string> subTypes = std::vector<std::string>()) {
static void Register(std::string name, bool hide = false, std::vector<std::string> subTypes = {}) {
FactoryBase<func>::DoRegister([](Arg1 a1, Arg2 a2) -> Base * { return new T(a1, a2); }, name, hide, subTypes);
}
};
@ -95,7 +95,7 @@ public:
}
template<class T>
static void Register(std::string name, bool hide = false, std::vector<std::string> subTypes = std::vector<std::string>()) {
static void Register(std::string name, bool hide = false, std::vector<std::string> subTypes = {}) {
FactoryBase<func>::DoRegister([](Arg1 a1) -> Base * { return new T(a1); }, name, hide, subTypes);
}
};
@ -111,7 +111,7 @@ public:
}
template<class T>
static void Register(std::string name, bool hide = false, std::vector<std::string> subTypes = std::vector<std::string>()) {
static void Register(std::string name, bool hide = false, std::vector<std::string> subTypes = {}) {
FactoryBase<func>::DoRegister([]() -> Base * { return new T; }, name, hide, subTypes);
}
};

View file

@ -278,11 +278,8 @@ bool SearchReplaceEngine::FindReplace(bool replace) {
if (selection_only)
// We're cycling through the selection, so don't muck with it
context->selectionController->SetActiveLine(diag);
else {
SubtitleSelection new_sel;
new_sel.insert(diag);
context->selectionController->SetSelectionAndActive(new_sel, diag);
}
else
context->selectionController->SetSelectionAndActive({ diag }, diag);
if (settings.field == SearchReplaceSettings::Field::TEXT)
context->textSelectionController->SetSelection(ms.start, ms.end);

View file

@ -48,9 +48,9 @@ class SubtitleFormat {
std::string name;
/// Get this format's wildcards for a load dialog
virtual std::vector<std::string> GetReadWildcards() const { return std::vector<std::string>(); }
virtual std::vector<std::string> GetReadWildcards() const { return {}; }
/// Get this format's wildcards for a save dialog
virtual std::vector<std::string> GetWriteWildcards() const { return std::vector<std::string>(); }
virtual std::vector<std::string> GetWriteWildcards() const { return {}; }
/// List of loaded subtitle formats
static std::vector<SubtitleFormat*> formats;

View file

@ -45,7 +45,7 @@ Thesaurus::~Thesaurus() {
}
std::vector<Thesaurus::Entry> Thesaurus::Lookup(std::string word) {
if (!impl.get()) return std::vector<Entry>();
if (!impl.get()) return {};
boost::to_lower(word);
return impl->Lookup(word);
}

View file

@ -456,7 +456,7 @@ void VideoContext::SaveTimecodes(agi::fs::path const& filename) {
void VideoContext::CloseTimecodes() {
ovr_fps = agi::vfr::Framerate();
timecodes_filename.clear();
OnSubtitlesCommit(0, std::set<const AssEntry*>());
OnSubtitlesCommit(0, std::set<const AssEntry*>());
TimecodesOpen(video_fps);
}

View file

@ -85,7 +85,7 @@ public:
int GetHeight() const override { return height; }
double GetDAR() const override { return 0; }
agi::vfr::Framerate GetFPS() const override { return fps; }
std::vector<int> GetKeyFrames() const override { return std::vector<int>(); }
std::vector<int> GetKeyFrames() const override { return {}; }
std::string GetColorSpace() const override { return "None"; }
std::string GetDecoderName() const override { return "Dummy Video Provider"; }
};

View file

@ -139,7 +139,7 @@ public:
int GetHeight() const override { return h; }
double GetDAR() const override { return 0; }
agi::vfr::Framerate GetFPS() const override { return fps; }
std::vector<int> GetKeyFrames() const override { return std::vector<int>(); }
std::vector<int> GetKeyFrames() const override { return {}; }
std::string GetColorSpace() const override { return "TV.601"; }
std::string GetDecoderName() const override { return "YU4MPEG"; }
bool WantsCaching() const override { return true; }

View file

@ -267,9 +267,7 @@ void VisualTool<FeatureType>::OnMouseEvent(wxMouseEvent &event) {
else {
if (!alt_down && features.size() > 1) {
sel_features.clear();
SubtitleSelection sel;
sel.insert(c->selectionController->GetActiveLine());
c->selectionController->SetSelectedSet(sel);
c->selectionController->SetSelectedSet({ c->selectionController->GetActiveLine() });
}
if (active_line && InitializeHold()) {
holding = true;

View file

@ -22,20 +22,6 @@
namespace util {
bool compare(std::string const& file1, std::string const& file2);
template<typename T>
static std::vector<T> make_vector(int len, ...) {
std::vector<T> vec(len);
va_list argp;
va_start(argp, len);
for (int i = 0; i < len; i++) {
vec[i] = va_arg(argp, T);
}
va_end(argp);
return vec;
}
int write_rand(const char *path);
int read_written_rand(const char *path);
}

View file

@ -29,7 +29,7 @@ using namespace agi::keyframe;
using namespace util;
TEST(lagi_keyframe, save) {
std::vector<int> kf = make_vector<int>(5, 0, 5, 70, 180, 300);
std::vector<int> kf = { 0, 5, 70, 180, 300 };
ASSERT_NO_THROW(Save("data/keyframe/out.txt", kf));
@ -46,7 +46,7 @@ TEST(lagi_keyframe, bad_files) {
}
TEST(lagi_keyframe, xvid) {
std::vector<int> expected = make_vector<int>(681,
std::vector<int> expected = {
0, 52, 53, 55, 57, 80, 114, 168, 182, 234, 240, 242, 244, 250, 251,
274, 290, 336, 364, 431, 465, 535, 596, 654, 700, 744, 976, 982, 983,
984, 985, 993, 994, 995, 996, 997, 998, 1006, 1007, 1008, 1009, 1022,
@ -111,13 +111,13 @@ TEST(lagi_keyframe, xvid) {
32594, 32801, 32820, 32881, 32989, 33060, 33130, 33162, 33233, 33273,
33325, 33344, 33362, 33388, 33408, 33438, 33458, 33561, 33644, 33700,
33880, 33923, 33969, 33982, 33991, 34010, 34025, 34043, 34055, 34065,
34082, 34102, 34112, 34122, 34142, 34158, 34170, 34187, 34211);
34082, 34102, 34112, 34122, 34142, 34158, 34170, 34187, 34211
};
std::vector<int> res;
ASSERT_NO_THROW(res = Load("data/keyframe/xvid.txt"));
EXPECT_TRUE(expected == res);
}
TEST(lagi_keyframe, x264) {

View file

@ -22,36 +22,36 @@ using namespace util;
TEST(lagi_wrap, no_wrapping_needed) {
for (int i = Wrap_Balanced_FirstLonger; i <= Wrap_Balanced_LastLonger; ++i)
ASSERT_NO_THROW(get_wrap_points(make_vector<int>(0), 100, (agi::WrapMode)i));
ASSERT_NO_THROW(get_wrap_points(std::vector<int>{}, 100, (agi::WrapMode)i));
for (int i = Wrap_Balanced_FirstLonger; i <= Wrap_Balanced_LastLonger; ++i)
ASSERT_NO_THROW(get_wrap_points(make_vector<int>(1, 10), 100, (agi::WrapMode)i));
ASSERT_NO_THROW(get_wrap_points(std::vector<int>{ 10 }, 100, (agi::WrapMode)i));
for (int i = Wrap_Balanced_FirstLonger; i <= Wrap_Balanced_LastLonger; ++i)
EXPECT_TRUE(get_wrap_points(make_vector<int>(1, 99), 100, (agi::WrapMode)i).empty());
EXPECT_TRUE(get_wrap_points(std::vector<int>{ 99 }, 100, (agi::WrapMode)i).empty());
for (int i = Wrap_Balanced_FirstLonger; i <= Wrap_Balanced_LastLonger; ++i)
EXPECT_TRUE(get_wrap_points(make_vector<int>(4, 25, 25, 25, 24), 100, (agi::WrapMode)i).empty());
EXPECT_TRUE(get_wrap_points(std::vector<int>{ 25, 25, 25, 24 }, 100, (agi::WrapMode)i).empty());
for (int i = Wrap_Balanced_FirstLonger; i <= Wrap_Balanced_LastLonger; ++i)
EXPECT_TRUE(get_wrap_points(make_vector<int>(1, 101), 100, (agi::WrapMode)i).empty());
EXPECT_TRUE(get_wrap_points(std::vector<int>{ 101 }, 100, (agi::WrapMode)i).empty());
}
TEST(lagi_wrap, greedy) {
std::vector<size_t> ret;
ASSERT_NO_THROW(ret = get_wrap_points(make_vector<int>(2, 10, 10), 20, Wrap_Greedy));
ASSERT_NO_THROW(ret = get_wrap_points(std::vector<int>{ 10, 10 }, 20, Wrap_Greedy));
EXPECT_EQ(0, ret.size());
ASSERT_NO_THROW(ret = get_wrap_points(make_vector<int>(2, 10, 10), 19, Wrap_Greedy));
ASSERT_NO_THROW(ret = get_wrap_points(std::vector<int>{ 10, 10 }, 19, Wrap_Greedy));
ASSERT_EQ(1, ret.size());
EXPECT_EQ(1, ret[0]);
ASSERT_NO_THROW(ret = get_wrap_points(make_vector<int>(2, 10, 10), 9, Wrap_Greedy));
ASSERT_NO_THROW(ret = get_wrap_points(std::vector<int>{ 10, 10 }, 9, Wrap_Greedy));
ASSERT_EQ(1, ret.size());
EXPECT_EQ(1, ret[0]);
ASSERT_NO_THROW(ret = get_wrap_points(make_vector<int>(4, 5, 5, 5, 1), 15, Wrap_Greedy));
ASSERT_NO_THROW(ret = get_wrap_points(std::vector<int>{ 5, 5, 5, 1 }, 15, Wrap_Greedy));
ASSERT_EQ(1, ret.size());
EXPECT_EQ(3, ret[0]);
@ -62,7 +62,7 @@ TEST(lagi_wrap, greedy) {
EXPECT_EQ(6, ret[2]);
EXPECT_EQ(8, ret[3]);
ASSERT_NO_THROW(ret = get_wrap_points(make_vector<int>(9, 6, 7, 6, 8, 10, 10, 3, 4, 10), 20, Wrap_Greedy));
ASSERT_NO_THROW(ret = get_wrap_points(std::vector<int>{ 6, 7, 6, 8, 10, 10, 3, 4, 10 }, 20, Wrap_Greedy));
ASSERT_EQ(3, ret.size());
EXPECT_EQ(3, ret[0]);
EXPECT_EQ(5, ret[1]);
@ -72,26 +72,26 @@ TEST(lagi_wrap, greedy) {
TEST(lagi_wrap, first_longer) {
std::vector<size_t> ret;
ASSERT_NO_THROW(ret = get_wrap_points(make_vector<int>(2, 10, 10), 20, Wrap_Balanced_FirstLonger));
ASSERT_NO_THROW(ret = get_wrap_points(std::vector<int>{ 10, 10 }, 20, Wrap_Balanced_FirstLonger));
EXPECT_EQ(0, ret.size());
ASSERT_NO_THROW(ret = get_wrap_points(make_vector<int>(2, 10, 10), 19, Wrap_Balanced_FirstLonger));
ASSERT_NO_THROW(ret = get_wrap_points(std::vector<int>{ 10, 10 }, 19, Wrap_Balanced_FirstLonger));
ASSERT_EQ(1, ret.size());
EXPECT_EQ(1, ret[0]);
ASSERT_NO_THROW(ret = get_wrap_points(make_vector<int>(2, 10, 10), 9, Wrap_Balanced_FirstLonger));
ASSERT_NO_THROW(ret = get_wrap_points(std::vector<int>{ 10, 10 }, 9, Wrap_Balanced_FirstLonger));
ASSERT_EQ(1, ret.size());
EXPECT_EQ(1, ret[0]);
ASSERT_NO_THROW(ret = get_wrap_points(make_vector<int>(3, 5, 5, 1), 10, Wrap_Balanced_FirstLonger));
ASSERT_NO_THROW(ret = get_wrap_points(std::vector<int>{ 5, 5, 1 }, 10, Wrap_Balanced_FirstLonger));
ASSERT_EQ(1, ret.size());
EXPECT_EQ(2, ret[0]);
ASSERT_NO_THROW(ret = get_wrap_points(make_vector<int>(4, 5, 5, 5, 1), 15, Wrap_Balanced_FirstLonger));
ASSERT_NO_THROW(ret = get_wrap_points(std::vector<int>{ 5, 5, 5, 1 }, 15, Wrap_Balanced_FirstLonger));
ASSERT_EQ(1, ret.size());
EXPECT_EQ(2, ret[0]);
ASSERT_NO_THROW(ret = get_wrap_points(make_vector<int>(3, 6, 5, 5), 10, Wrap_Balanced_FirstLonger));
ASSERT_NO_THROW(ret = get_wrap_points(std::vector<int>{ 6, 5, 5 }, 10, Wrap_Balanced_FirstLonger));
ASSERT_EQ(1, ret.size());
EXPECT_EQ(1, ret[0]);
}
@ -99,26 +99,26 @@ TEST(lagi_wrap, first_longer) {
TEST(lagi_wrap, last_longer) {
std::vector<size_t> ret;
ASSERT_NO_THROW(ret = get_wrap_points(make_vector<int>(2, 10, 10), 20, Wrap_Balanced_LastLonger));
ASSERT_NO_THROW(ret = get_wrap_points(std::vector<int>{ 10, 10 }, 20, Wrap_Balanced_LastLonger));
EXPECT_EQ(0, ret.size());
ASSERT_NO_THROW(ret = get_wrap_points(make_vector<int>(2, 10, 10), 19, Wrap_Balanced_LastLonger));
ASSERT_NO_THROW(ret = get_wrap_points(std::vector<int>{ 10, 10 }, 19, Wrap_Balanced_LastLonger));
ASSERT_EQ(1, ret.size());
EXPECT_EQ(1, ret[0]);
ASSERT_NO_THROW(ret = get_wrap_points(make_vector<int>(2, 10, 10), 9, Wrap_Balanced_LastLonger));
ASSERT_NO_THROW(ret = get_wrap_points(std::vector<int>{ 10, 10 }, 9, Wrap_Balanced_LastLonger));
ASSERT_EQ(1, ret.size());
EXPECT_EQ(1, ret[0]);
ASSERT_NO_THROW(ret = get_wrap_points(make_vector<int>(3, 5, 5, 1), 10, Wrap_Balanced_LastLonger));
ASSERT_NO_THROW(ret = get_wrap_points(std::vector<int>{ 5, 5, 1 }, 10, Wrap_Balanced_LastLonger));
ASSERT_EQ(1, ret.size());
EXPECT_EQ(1, ret[0]);
ASSERT_NO_THROW(ret = get_wrap_points(make_vector<int>(4, 5, 5, 5, 1), 15, Wrap_Balanced_LastLonger));
ASSERT_NO_THROW(ret = get_wrap_points(std::vector<int>{ 5, 5, 5, 1 }, 15, Wrap_Balanced_LastLonger));
ASSERT_EQ(1, ret.size());
EXPECT_EQ(1, ret[0]);
ASSERT_NO_THROW(ret = get_wrap_points(make_vector<int>(3, 5, 5, 6), 10, Wrap_Balanced_LastLonger));
ASSERT_NO_THROW(ret = get_wrap_points(std::vector<int>{ 5, 5, 6 }, 10, Wrap_Balanced_LastLonger));
ASSERT_EQ(1, ret.size());
EXPECT_EQ(2, ret[0]);
}
@ -126,26 +126,26 @@ TEST(lagi_wrap, last_longer) {
TEST(lagi_wrap, balanced) {
std::vector<size_t> ret;
ASSERT_NO_THROW(ret = get_wrap_points(make_vector<int>(2, 10, 10), 20, Wrap_Balanced));
ASSERT_NO_THROW(ret = get_wrap_points(std::vector<int>{ 10, 10 }, 20, Wrap_Balanced));
EXPECT_EQ(0, ret.size());
ASSERT_NO_THROW(ret = get_wrap_points(make_vector<int>(2, 10, 10), 19, Wrap_Balanced));
ASSERT_NO_THROW(ret = get_wrap_points(std::vector<int>{ 10, 10 }, 19, Wrap_Balanced));
ASSERT_EQ(1, ret.size());
EXPECT_EQ(1, ret[0]);
ASSERT_NO_THROW(ret = get_wrap_points(make_vector<int>(2, 10, 10), 9, Wrap_Balanced));
ASSERT_NO_THROW(ret = get_wrap_points(std::vector<int>{ 10, 10 }, 9, Wrap_Balanced));
ASSERT_EQ(1, ret.size());
EXPECT_EQ(1, ret[0]);
ASSERT_NO_THROW(ret = get_wrap_points(make_vector<int>(3, 5, 5, 1), 10, Wrap_Balanced));
ASSERT_NO_THROW(ret = get_wrap_points(std::vector<int>{ 5, 5, 1 }, 10, Wrap_Balanced));
ASSERT_EQ(1, ret.size());
EXPECT_EQ(1, ret[0]);
ASSERT_NO_THROW(ret = get_wrap_points(make_vector<int>(4, 5, 5, 5, 1), 15, Wrap_Balanced));
ASSERT_NO_THROW(ret = get_wrap_points(std::vector<int>{ 5, 5, 5, 1 }, 15, Wrap_Balanced));
ASSERT_EQ(1, ret.size());
EXPECT_EQ(2, ret[0]);
ASSERT_NO_THROW(ret = get_wrap_points(make_vector<int>(9, 6, 7, 6, 8, 10, 10, 3, 4, 10), 20, Wrap_Balanced));
ASSERT_NO_THROW(ret = get_wrap_points(std::vector<int>{ 6, 7, 6, 8, 10, 10, 3, 4, 10 }, 20, Wrap_Balanced));
ASSERT_EQ(3, ret.size());
EXPECT_EQ(3, ret[0]);
EXPECT_EQ(5, ret[1]);

View file

@ -34,7 +34,7 @@ using namespace util;
TEST(lagi_vfr, constructors_good) {
EXPECT_NO_THROW(Framerate(1.));
EXPECT_NO_THROW(Framerate(Framerate(1.)));
EXPECT_NO_THROW(Framerate(make_vector<int>(2, 0, 10)));
EXPECT_NO_THROW(Framerate({ 0, 10 }));
EXPECT_NO_THROW(Framerate("data/vfr/in/v1_start_equals_end.txt"));
EXPECT_NO_THROW(Framerate("data/vfr/in/v1_whitespace.txt"));
@ -48,9 +48,9 @@ TEST(lagi_vfr, constructors_bad_cfr) {
}
TEST(lagi_vfr, constructors_bad_timecodes) {
EXPECT_THROW(Framerate(make_vector<int>(0)), TooFewTimecodes);
EXPECT_THROW(Framerate(make_vector<int>(1, 0)), TooFewTimecodes);
EXPECT_THROW(Framerate(make_vector<int>(2, 10, 0)), UnorderedTimecodes);
EXPECT_THROW(Framerate(std::initializer_list<int>{}), TooFewTimecodes);
EXPECT_THROW(Framerate({ 0 }), TooFewTimecodes);
EXPECT_THROW(Framerate({ 10, 0 }), UnorderedTimecodes);
}
TEST(lagi_vfr, constructors_bad_v1) {
@ -168,7 +168,7 @@ TEST(lagi_vfr, cfr_round_trip_end) {
TEST(lagi_vfr, vfr_round_trip_exact) {
Framerate fps;
ASSERT_NO_THROW(fps = Framerate(make_vector<int>(7, 0, 1000, 1500, 2000, 2001, 2002, 2003)));
ASSERT_NO_THROW(fps = Framerate({ 0, 1000, 1500, 2000, 2001, 2002, 2003 }));
for (int i = -10; i < 11; i++) {
EXPECT_EQ(i, fps.FrameAtTime(fps.TimeAtFrame(i)));
}
@ -176,7 +176,7 @@ TEST(lagi_vfr, vfr_round_trip_exact) {
TEST(lagi_vfr, vfr_round_trip_start) {
Framerate fps;
ASSERT_NO_THROW(fps = Framerate(make_vector<int>(7, 0, 1000, 1500, 2000, 2001, 2002, 2003)));
ASSERT_NO_THROW(fps = Framerate({ 0, 1000, 1500, 2000, 2001, 2002, 2003 }));
for (int i = -10; i < 11; i++) {
EXPECT_EQ(i, fps.FrameAtTime(fps.TimeAtFrame(i, START), START));
}
@ -184,7 +184,7 @@ TEST(lagi_vfr, vfr_round_trip_start) {
TEST(lagi_vfr, vfr_round_trip_end) {
Framerate fps;
ASSERT_NO_THROW(fps = Framerate(make_vector<int>(7, 0, 1000, 1500, 2000, 2001, 2002, 2003)));
ASSERT_NO_THROW(fps = Framerate({ 0, 1000, 1500, 2000, 2001, 2002, 2003 }));
for (int i = -10; i < 11; i++) {
EXPECT_EQ(i, fps.FrameAtTime(fps.TimeAtFrame(i, END), END));
}
@ -192,7 +192,7 @@ TEST(lagi_vfr, vfr_round_trip_end) {
TEST(lagi_vfr, vfr_time_at_frame_exact) {
Framerate fps;
ASSERT_NO_THROW(fps = Framerate(make_vector<int>(5, 0, 1000, 1500, 2000, 2001)));
ASSERT_NO_THROW(fps = Framerate({ 0, 1000, 1500, 2000, 2001 }));
EXPECT_EQ(0, fps.TimeAtFrame(0));
EXPECT_EQ(1000, fps.TimeAtFrame(1));
EXPECT_EQ(1500, fps.TimeAtFrame(2));
@ -202,7 +202,7 @@ TEST(lagi_vfr, vfr_time_at_frame_exact) {
TEST(lagi_vfr, vfr_time_at_frame_start) {
Framerate fps;
ASSERT_NO_THROW(fps = Framerate(make_vector<int>(7, 0, 1000, 1500, 2000, 2001, 2002, 2003)));
ASSERT_NO_THROW(fps = Framerate({ 0, 1000, 1500, 2000, 2001, 2002, 2003 }));
EXPECT_GE(0, fps.TimeAtFrame(0, START));
EXPECT_RANGE(1, 1000, fps.TimeAtFrame(1, START));
EXPECT_RANGE(1001, 1500, fps.TimeAtFrame(2, START));
@ -214,7 +214,7 @@ TEST(lagi_vfr, vfr_time_at_frame_start) {
TEST(lagi_vfr, vfr_time_at_frame_end) {
Framerate fps;
ASSERT_NO_THROW(fps = Framerate(make_vector<int>(7, 0, 1000, 1500, 2000, 2001, 2002, 2003)));
ASSERT_NO_THROW(fps = Framerate({ 0, 1000, 1500, 2000, 2001, 2002, 2003 }));
EXPECT_RANGE(1, 1000, fps.TimeAtFrame(0, END));
EXPECT_RANGE(1001, 1500, fps.TimeAtFrame(1, END));
EXPECT_RANGE(1501, 2000, fps.TimeAtFrame(2, END));
@ -226,7 +226,7 @@ TEST(lagi_vfr, vfr_time_at_frame_end) {
TEST(lagi_vfr, vfr_time_at_frame_outside_range) {
Framerate fps;
ASSERT_NO_THROW(fps = Framerate(make_vector<int>(3, 0, 100, 200)));
ASSERT_NO_THROW(fps = Framerate({ 0, 100, 200 }));
EXPECT_GT(0, fps.TimeAtFrame(-1));
EXPECT_EQ(0, fps.TimeAtFrame(0));
EXPECT_EQ(100, fps.TimeAtFrame(1));
@ -242,7 +242,7 @@ TEST(lagi_vfr, vfr_time_at_frame_outside_range) {
TEST(lagi_vfr, vfr_frame_at_time_exact) {
Framerate fps;
ASSERT_NO_THROW(fps = Framerate(make_vector<int>(7, 0, 1000, 1500, 2000, 2001, 2002, 2003)));
ASSERT_NO_THROW(fps = Framerate({ 0, 1000, 1500, 2000, 2001, 2002, 2003 }));
EXPECT_GT(0, fps.FrameAtTime(-1));
EXPECT_EQ(0, fps.FrameAtTime(0));
EXPECT_EQ(0, fps.FrameAtTime(999));
@ -258,7 +258,7 @@ TEST(lagi_vfr, vfr_frame_at_time_exact) {
}
TEST(lagi_vfr, vfr_frame_at_time_start) {
Framerate fps;
ASSERT_NO_THROW(fps = Framerate(make_vector<int>(7, 0, 1000, 1500, 2000, 2001, 2002, 2003)));
ASSERT_NO_THROW(fps = Framerate({ 0, 1000, 1500, 2000, 2001, 2002, 2003 }));
EXPECT_GE(0, fps.FrameAtTime(-1, START));
EXPECT_EQ(0, fps.FrameAtTime(0, START));
EXPECT_EQ(1, fps.FrameAtTime(1, START));
@ -315,7 +315,7 @@ TEST(lagi_vfr, validate_save) {
TEST(lagi_vfr, save_vfr_nolen) {
Framerate fps;
ASSERT_NO_THROW(fps = Framerate(make_vector<int>(3, 0, 100, 200)));
ASSERT_NO_THROW(fps = Framerate({ 0, 100, 200 }));
ASSERT_NO_THROW(fps.Save("data/vfr/out/v2_nolen.txt"));
EXPECT_TRUE(validate_save("data/vfr/in/v2_nolen.txt", "data/vfr/out/v2_nolen.txt"));
@ -323,7 +323,7 @@ TEST(lagi_vfr, save_vfr_nolen) {
TEST(lagi_vfr, save_vfr_len) {
Framerate fps;
ASSERT_NO_THROW(fps = Framerate(make_vector<int>(3, 0, 100, 200)));
ASSERT_NO_THROW(fps = Framerate({ 0, 100, 200 }));
ASSERT_NO_THROW(fps.Save("data/vfr/out/v2_len_3_10.txt", 10));
EXPECT_TRUE(validate_save("data/vfr/in/v2_len_3_10.txt", "data/vfr/out/v2_len_3_10.txt", 3));
@ -378,14 +378,14 @@ TEST(lagi_vfr, load_v1_save_v2_ovr) {
TEST(lagi_vfr, nonzero_start_time) {
Framerate fps;
ASSERT_NO_THROW(fps = Framerate(make_vector<int>(5, 10, 20, 30, 40, 50)));
ASSERT_NO_THROW(fps = Framerate({ 10, 20, 30, 40, 50 }));
EXPECT_EQ(0, fps.TimeAtFrame(0, EXACT));
EXPECT_EQ(10, fps.TimeAtFrame(1, EXACT));
EXPECT_EQ(20, fps.TimeAtFrame(2, EXACT));
EXPECT_EQ(30, fps.TimeAtFrame(3, EXACT));
EXPECT_EQ(40, fps.TimeAtFrame(4, EXACT));
ASSERT_NO_THROW(fps = Framerate(make_vector<int>(5, -10, 20, 30, 40, 50)));
ASSERT_NO_THROW(fps = Framerate({ -10, 20, 30, 40, 50 }));
EXPECT_EQ(0, fps.TimeAtFrame(0, EXACT));
EXPECT_EQ(30, fps.TimeAtFrame(1, EXACT));
EXPECT_EQ(40, fps.TimeAtFrame(2, EXACT));
@ -420,7 +420,7 @@ TEST(lagi_vfr, no_intermediate_overflow) {
TEST(lagi_vfr, duplicate_timestamps) {
Framerate fps;
ASSERT_NO_THROW(fps = Framerate(make_vector<int>(6, 0, 0, 1, 2, 2, 3)));
ASSERT_NO_THROW(fps = Framerate({ 0, 0, 1, 2, 2, 3 }));
EXPECT_EQ(1, fps.FrameAtTime(0, EXACT));
EXPECT_EQ(2, fps.FrameAtTime(1, EXACT));
@ -434,7 +434,7 @@ TEST(lagi_vfr, duplicate_timestamps) {
EXPECT_EQ(2, fps.TimeAtFrame(4, EXACT));
EXPECT_EQ(3, fps.TimeAtFrame(5, EXACT));
ASSERT_NO_THROW(fps = Framerate(make_vector<int>(5, 0, 100, 100, 200, 300)));
ASSERT_NO_THROW(fps = Framerate({ 0, 100, 100, 200, 300 }));
EXPECT_EQ(0, fps.FrameAtTime(0, EXACT));
EXPECT_EQ(0, fps.FrameAtTime(99, EXACT));