Add test_arf_interval()

Test whether the intervals between two consecutive ARFs in display
order have the specified minimum kMinArfInterval

Bug: b/221916304
Change-Id: I7c8a35fcfe5ca4badba8c451dae1502039afe44c
diff --git a/av1/ratectrl_qmode.h b/av1/ratectrl_qmode.h
index 6c928bf..c53f4e1 100644
--- a/av1/ratectrl_qmode.h
+++ b/av1/ratectrl_qmode.h
@@ -23,6 +23,7 @@
 
 constexpr int kLayerDepthOffset = 1;
 constexpr int kMinIntervalToAddArf = 3;
+constexpr int kMinArfInterval = (kMinIntervalToAddArf + 1) / 2;
 
 struct TplFrameDepStats {
   int unit_size;  // equivalent to min_block_size
diff --git a/test/ratectrl_qmode_test.cc b/test/ratectrl_qmode_test.cc
index 2780141..aa0851d 100644
--- a/test/ratectrl_qmode_test.cc
+++ b/test/ratectrl_qmode_test.cc
@@ -10,6 +10,7 @@
  */
 
 #include <array>
+#include <algorithm>
 #include <memory>
 #include <vector>
 
@@ -70,9 +71,24 @@
   }
 }
 
+void test_arf_interval(const GopStruct &gop_struct) {
+  std::vector<int> arf_order_idx_list;
+  for (const auto &gop_frame : gop_struct.gop_frame_list) {
+    if (gop_frame.is_arf_frame) {
+      arf_order_idx_list.push_back(gop_frame.order_idx);
+    }
+  }
+  std::sort(arf_order_idx_list.begin(), arf_order_idx_list.end());
+  int arf_count = static_cast<int>(arf_order_idx_list.size());
+  for (int i = 1; i < arf_count; ++i) {
+    int arf_interval = arf_order_idx_list[i] - arf_order_idx_list[i - 1];
+    EXPECT_GE(arf_interval, kMinArfInterval);
+  }
+}
+
 TEST(RateControlQModeTest, ConstructGopARF) {
   int show_frame_count = 16;
-  const int max_ref_frames = 7;
+  const int max_ref_frames = 8;
   const bool has_key_frame = false;
   RefFrameManager ref_frame_manager(max_ref_frames);
   GopStruct gop_struct =
@@ -82,11 +98,12 @@
   const int max_layer_depth =
       ref_frame_manager.ForwardMaxSize() + kLayerDepthOffset;
   test_layer_depth(gop_struct, max_layer_depth);
+  test_arf_interval(gop_struct);
 }
 
 TEST(RateControlQModeTest, ConstructGopKey) {
   int show_frame_count = 16;
-  int max_ref_frames = 7;
+  int max_ref_frames = 8;
   int has_key_frame = 1;
   RefFrameManager ref_frame_manager(max_ref_frames);
   GopStruct gop_struct =
@@ -96,6 +113,7 @@
   const int max_layer_depth =
       ref_frame_manager.ForwardMaxSize() + kLayerDepthOffset;
   test_layer_depth(gop_struct, max_layer_depth);
+  test_arf_interval(gop_struct);
 }
 
 static TplBlockStats create_toy_tpl_block_stats(int h, int w, int r, int c,