1
0
Fork 0
mirror of https://github.com/bolero-MURAKAMI/Sprout synced 2025-08-03 12:49:50 +00:00

fix rotate_copy

This commit is contained in:
Mitsuru Kariya 2015-04-08 00:24:12 +09:00
parent befe29adf0
commit edc41403f6
3 changed files with 119 additions and 31 deletions

View file

@ -24,21 +24,21 @@ namespace testspr {
{
SPROUT_STATIC_CONSTEXPR auto rotated = sprout::rotate(
arr1,
sprout::begin(arr1) + 5
sprout::begin(arr1) + 4
);
TESTSPR_BOTH_ASSERT(testspr::equal(
rotated,
array<int, 10>{{6, 7, 8, 9, 10, 1, 2, 3, 4, 5}}
array<int, 10>{{5, 6, 7, 8, 9, 10, 1, 2, 3, 4}}
));
}
{
SPROUT_STATIC_CONSTEXPR auto rotated = sprout::fit::rotate(
arr1,
sprout::begin(arr1) + 5
sprout::begin(arr1) + 4
);
TESTSPR_BOTH_ASSERT(testspr::equal(
rotated,
array<int, 10>{{6, 7, 8, 9, 10, 1, 2, 3, 4, 5}}
array<int, 10>{{5, 6, 7, 8, 9, 10, 1, 2, 3, 4}}
));
}
// rotate
@ -46,29 +46,29 @@ namespace testspr {
{
SPROUT_STATIC_CONSTEXPR auto rotated = sprout::rotate(
sprout::sub(arr1, 2, 8),
sprout::begin(arr1) + 5
sprout::begin(arr1) + 4
);
TESTSPR_BOTH_ASSERT(testspr::equal(
rotated,
array<int, 6>{{6, 7, 8, 3, 4, 5}}
array<int, 6>{{5, 6, 7, 8, 3, 4}}
));
TESTSPR_BOTH_ASSERT(testspr::equal(
sprout::get_internal(rotated),
array<int, 10>{{1, 2, 6, 7, 8, 3, 4, 5, 9, 10}}
array<int, 10>{{1, 2, 5, 6, 7, 8, 3, 4, 9, 10}}
));
}
{
SPROUT_STATIC_CONSTEXPR auto rotated = sprout::fit::rotate(
sprout::sub(arr1, 2, 8),
sprout::begin(arr1) + 5
sprout::begin(arr1) + 4
);
TESTSPR_BOTH_ASSERT(testspr::equal(
rotated,
array<int, 6>{{6, 7, 8, 3, 4, 5}}
array<int, 6>{{5, 6, 7, 8, 3, 4}}
));
TESTSPR_BOTH_ASSERT(testspr::equal(
sprout::get_internal(rotated),
array<int, 10>{{1, 2, 6, 7, 8, 3, 4, 5, 9, 10}}
array<int, 10>{{1, 2, 5, 6, 7, 8, 3, 4, 9, 10}}
));
}
}

View file

@ -26,25 +26,25 @@ namespace testspr {
{
SPROUT_STATIC_CONSTEXPR auto rotated = sprout::rotate_copy(
sprout::begin(arr1) + 2,
sprout::begin(arr1) + 5,
sprout::begin(arr1) + 4,
sprout::begin(arr1) + 8,
arr2
);
TESTSPR_BOTH_ASSERT(testspr::equal(
rotated,
array<int, 10>{{6, 7, 8, 3, 4, 5, 0, 0, 0, 0}}
array<int, 10>{{5, 6, 7, 8, 3, 4, 0, 0, 0, 0}}
));
}
{
SPROUT_STATIC_CONSTEXPR auto rotated = sprout::fit::rotate_copy(
sprout::begin(arr1) + 2,
sprout::begin(arr1) + 5,
sprout::begin(arr1) + 4,
sprout::begin(arr1) + 8,
arr2
);
TESTSPR_BOTH_ASSERT(testspr::equal(
rotated,
array<int, 6>{{6, 7, 8, 3, 4, 5}}
array<int, 6>{{5, 6, 7, 8, 3, 4}}
));
}
// rotate in range [2 .. 8)
@ -52,25 +52,25 @@ namespace testspr {
{
SPROUT_STATIC_CONSTEXPR auto rotated = sprout::rotate_copy(
sprout::begin(arr1) + 2,
sprout::begin(arr1) + 5,
sprout::begin(arr1) + 8,
sprout::begin(arr1) + 4,
sprout::begin(arr1) + 7,
arr3
);
TESTSPR_BOTH_ASSERT(testspr::equal(
rotated,
array<int, 4>{{6, 7, 8, 3}}
array<int, 4>{{5, 6, 7, 3}}
));
}
{
SPROUT_STATIC_CONSTEXPR auto rotated = sprout::fit::rotate_copy(
sprout::begin(arr1) + 2,
sprout::begin(arr1) + 5,
sprout::begin(arr1) + 8,
sprout::begin(arr1) + 4,
sprout::begin(arr1) + 7,
arr3
);
TESTSPR_BOTH_ASSERT(testspr::equal(
rotated,
array<int, 4>{{6, 7, 8, 3}}
array<int, 4>{{5, 6, 7, 3}}
));
}
// rotate in range [2 .. 8)
@ -78,33 +78,119 @@ namespace testspr {
{
SPROUT_STATIC_CONSTEXPR auto rotated = sprout::rotate_copy(
sprout::begin(arr1) + 2,
sprout::begin(arr1) + 5,
sprout::begin(arr1) + 4,
sprout::begin(arr1) + 8,
sprout::sub(arr2, 2, 8)
);
TESTSPR_BOTH_ASSERT(testspr::equal(
rotated,
array<int, 6>{{6, 7, 8, 3, 4, 5}}
array<int, 6>{{5, 6, 7, 8, 3, 4}}
));
TESTSPR_BOTH_ASSERT(testspr::equal(
sprout::get_internal(rotated),
array<int, 10>{{0, 0, 6, 7, 8, 3, 4, 5, 0, 0}}
array<int, 10>{{0, 0, 5, 6, 7, 8, 3, 4, 0, 0}}
));
}
{
SPROUT_STATIC_CONSTEXPR auto rotated = sprout::fit::rotate_copy(
sprout::begin(arr1) + 2,
sprout::begin(arr1) + 5,
sprout::begin(arr1) + 4,
sprout::begin(arr1) + 8,
sprout::sub(arr2, 2, 8)
);
TESTSPR_BOTH_ASSERT(testspr::equal(
rotated,
array<int, 6>{{6, 7, 8, 3, 4, 5}}
array<int, 6>{{5, 6, 7, 8, 3, 4}}
));
TESTSPR_BOTH_ASSERT(testspr::equal(
sprout::get_internal(rotated),
array<int, 10>{{0, 0, 6, 7, 8, 3, 4, 5, 0, 0}}
array<int, 10>{{0, 0, 5, 6, 7, 8, 3, 4, 0, 0}}
));
}
// rotate in range [2 .. 8)
{
SPROUT_STATIC_CONSTEXPR auto rotated = sprout::rotate_copy(
testspr::reduct_forward(sprout::begin(arr1) + 2),
testspr::reduct_forward(sprout::begin(arr1) + 4),
testspr::reduct_forward(sprout::begin(arr1) + 8),
arr2
);
TESTSPR_BOTH_ASSERT(testspr::equal(
rotated,
array<int, 10>{{5, 6, 7, 8, 3, 4, 0, 0, 0, 0}}
));
}
{
SPROUT_STATIC_CONSTEXPR auto rotated = sprout::fit::rotate_copy(
testspr::reduct_forward(sprout::begin(arr1) + 2),
testspr::reduct_forward(sprout::begin(arr1) + 4),
testspr::reduct_forward(sprout::begin(arr1) + 8),
arr2
);
TESTSPR_BOTH_ASSERT(testspr::equal(
rotated,
array<int, 6>{{5, 6, 7, 8, 3, 4}}
));
}
// rotate in range [2 .. 8)
// overrun from output range
{
SPROUT_STATIC_CONSTEXPR auto rotated = sprout::rotate_copy(
testspr::reduct_forward(sprout::begin(arr1) + 2),
testspr::reduct_forward(sprout::begin(arr1) + 4),
testspr::reduct_forward(sprout::begin(arr1) + 7),
arr3
);
TESTSPR_BOTH_ASSERT(testspr::equal(
rotated,
array<int, 4>{{5, 6, 7, 3}}
));
}
{
SPROUT_STATIC_CONSTEXPR auto rotated = sprout::fit::rotate_copy(
testspr::reduct_forward(sprout::begin(arr1) + 2),
testspr::reduct_forward(sprout::begin(arr1) + 4),
testspr::reduct_forward(sprout::begin(arr1) + 7),
arr3
);
TESTSPR_BOTH_ASSERT(testspr::equal(
rotated,
array<int, 4>{{5, 6, 7, 3}}
));
}
// rotate in range [2 .. 8)
// to sub range
{
SPROUT_STATIC_CONSTEXPR auto rotated = sprout::rotate_copy(
testspr::reduct_forward(sprout::begin(arr1) + 2),
testspr::reduct_forward(sprout::begin(arr1) + 4),
testspr::reduct_forward(sprout::begin(arr1) + 8),
sprout::sub(arr2, 2, 8)
);
TESTSPR_BOTH_ASSERT(testspr::equal(
rotated,
array<int, 6>{{5, 6, 7, 8, 3, 4}}
));
TESTSPR_BOTH_ASSERT(testspr::equal(
sprout::get_internal(rotated),
array<int, 10>{{0, 0, 5, 6, 7, 8, 3, 4, 0, 0}}
));
}
{
SPROUT_STATIC_CONSTEXPR auto rotated = sprout::fit::rotate_copy(
testspr::reduct_forward(sprout::begin(arr1) + 2),
testspr::reduct_forward(sprout::begin(arr1) + 4),
testspr::reduct_forward(sprout::begin(arr1) + 8),
sprout::sub(arr2, 2, 8)
);
TESTSPR_BOTH_ASSERT(testspr::equal(
rotated,
array<int, 6>{{5, 6, 7, 8, 3, 4}}
));
TESTSPR_BOTH_ASSERT(testspr::equal(
sprout::get_internal(rotated),
array<int, 10>{{0, 0, 5, 6, 7, 8, 3, 4, 0, 0}}
));
}
}