Size: 1919 bytes.


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
// cs/apps/trycopilot.ai/scene_animator_test.gpt.cc
// cs/apps/trycopilot.ai/scene_animator_test.cc
#include "cs/apps/trycopilot.ai/scene_animator.hh"

#include "gmock/gmock.h"
#include "gtest/gtest.h"

using ::cs::apps::trycopilotai::SceneAnimator;
using ::testing::Eq;
using ::testing::FloatEq;
using ::testing::Gt;
using ::testing::IsFalse;
using ::testing::IsTrue;
using ::testing::Matcher;
using ::testing::StrEq;

class SceneAnimatorTest : public ::testing::Test {
 protected:
  SceneAnimatorTest() {}
  void RenderTest(unsigned int width, unsigned int height,
                  unsigned int num_frames) {
    // Build scene
    std::tuple<uint, uint> film_dimensions(width, height);
    SceneAnimator animator(num_frames, film_dimensions);
    // Render out frames
    std::vector<Film> frames;
    [[maybe_unused]]
    const auto render_time_ms =
        cs::util::timeit([&frames, &animator]() {
          frames = animator.render_all_frames();
        });
    EXPECT_THAT(render_time_ms, Gt(0));
  }
};

#define RENDER_TEST(width, height, num_frames) \
  TEST_F(SceneAnimatorTest,                    \
         At##width##x##height##num_frames) {   \
    RenderTest(width, height, num_frames);     \
  }

RENDER_TEST(256, 256, 1);

RENDER_TEST(255, 256, 1);

RENDER_TEST(250, 256, 1);

RENDER_TEST(240, 256, 1);

RENDER_TEST(230, 255, 1);

RENDER_TEST(225, 255, 1);

RENDER_TEST(224, 255, 1);

RENDER_TEST(223, 255, 1);

RENDER_TEST(200, 255, 1);

TEST_F(SceneAnimatorTest, CallbackInvoked) {
  std::tuple<uint, uint> film_dimensions(8, 8);
  SceneAnimator animator(1, film_dimensions);
  unsigned int callbacks = 0;
  auto frames = animator.render_all_frames(
      [&](unsigned int /*render_time_ms*/,
          unsigned int index, unsigned int total) {
        callbacks++;
        EXPECT_EQ(index, 1u);
        EXPECT_EQ(total, 1u);
      });
  EXPECT_EQ(callbacks, 1u);
  EXPECT_EQ(frames.size(), 1u);
}
v0 (commit) © 2025 @p13i.io | Load balancer proxied to: cs-code-viewer-3:8080 in 4ms.