code: def test_roc():
      indicator_name = "ROC"
      # Test Case 1: constant prices
      cols = get_cols_name(1)
      tech_params.roc_period = 3
      data_df = pd.DataFrame(index=dates, columns=cols, data=1)
      tech_ind.create_tech_ind(data_df, indicator_name, tech_params)
      expected_signal_df = pd.DataFrame(
          index=dates,
          columns=[
              " ".join([col, indicator_name, "Signal"]) for col in cols
          ],
          data=-1,
      )
      expected_df = pd.DataFrame(
          index=dates,
          columns=[" ".join([col, indicator_name]) for col in cols],
          data=0,
      )
      expected_signal_df.iloc[: tech_params.roc_period] = np.nan
      expected_df.iloc[: tech_params.roc_period] = np.nan
      df = tech_ind.get_techind()
      signal_df = tech_ind.get_signal()
  
      assert_frame_equal(df, expected_df)
      assert_frame_equal(signal_df, expected_signal_df)
  
      # Test Case 2: Increasing prices, fixed rate
      cols = get_cols_name(1)
      tech_params.roc_period = 1
      data_df = pd.DataFrame(
          index=dates, columns=cols, data=[1, 2, 4, 8, 16, 32, 64, 128]
      )
      tech_ind.create_tech_ind(data_df, indicator_name, tech_params)
      expected_signal_df = pd.DataFrame(
          index=dates,
          columns=[
              " ".join([col, indicator_name, "Signal"]) for col in cols
          ],
          data=1,
      )
      expected_df = pd.DataFrame(
          index=dates,
          columns=[" ".join([col, indicator_name]) for col in cols],
          data=1,
      )
      expected_signal_df.iloc[: tech_params.roc_period] = np.nan
      expected_df.iloc[: tech_params.roc_period] = np.nan
      df = tech_ind.get_techind()
      signal_df = tech_ind.get_signal()
  
      assert_frame_equal(df, expected_df)
      assert_frame_equal(signal_df, expected_signal_df)
  
      tech_params.roc_period = 2
      data_df = pd.DataFrame(
          index=dates, columns=cols, data=[1, 2, 4, 8, 16, 32, 64, 128]
      )
      tech_ind.create_tech_ind(data_df, indicator_name, tech_params)
      expected_signal_df = pd.DataFrame(
          index=dates,
          columns=[
              " ".join([col, indicator_name, "Signal"]) for col in cols
          ],
          data=1,
      )
      expected_df = pd.DataFrame(
          index=dates,
          columns=[" ".join([col, indicator_name]) for col in cols],
          data=3,
      )
      expected_signal_df.iloc[: tech_params.roc_period] = np.nan
      expected_df.iloc[: tech_params.roc_period] = np.nan
      df = tech_ind.get_techind()
      signal_df = tech_ind.get_signal()
  
      assert_frame_equal(df, expected_df)
      assert_frame_equal(signal_df, expected_signal_df)
  
      tech_params.roc_period = 3
      data_df = pd.DataFrame(
          index=dates, columns=cols, data=[1, 2, 4, 8, 16, 32, 64, 128]
      )
      tech_ind.create_tech_ind(data_df, indicator_name, tech_params)
      expected_signal_df = pd.DataFrame(
          index=dates,
          columns=[
              " ".join([col, indicator_name, "Signal"]) for col in cols
          ],
          data=1,
      )
      expected_df = pd.DataFrame(
          index=dates,
          columns=[" ".join([col, indicator_name]) for col in cols],
          data=7,
      )
      expected_signal_df.iloc[: tech_params.roc_period] = np.nan
      expected_df.iloc[: tech_params.roc_period] = np.nan
      df = tech_ind.get_techind()
      signal_df = tech_ind.get_signal()
  
      assert_frame_equal(df, expected_df)
      assert_frame_equal(signal_df, expected_signal_df)
  
      # Test Case 3: Missing values
      cols = get_cols_name(1)
      tech_params.roc_period = 1
      data_df = pd.DataFrame(
          index=dates, columns=cols, data=[1, 2, 4, 8, 16, 32, 64, 128]
      )
      data_df.iloc[3] = np.nan
      tech_ind.create_tech_ind(data_df, indicator_name, tech_params)
      expected_signal_df = pd.DataFrame(
          index=dates,
          columns=[
              " ".join([col, indicator_name, "Signal"]) for col in cols
          ],
          data=[1, 1, 1, -1, 1, 1, 1, 1],
      )
      expected_df = pd.DataFrame(
          index=dates,
          columns=[" ".join([col, indicator_name]) for col in cols],
          data=[1, 1, 1, 0, 3, 1, 1, 1],
      )
      expected_signal_df.iloc[: tech_params.roc_period] = np.nan
      expected_df.iloc[: tech_params.roc_period] = np.nan
      df = tech_ind.get_techind()
      signal_df = tech_ind.get_signal()
  
      assert_frame_equal(df, expected_df)
      assert_frame_equal(signal_df, expected_signal_df)
  
file_path: finmarketpy/tests/test_techindicator.py
imports: import pytest
  import pandas
  import numpy
  from pandas.testing import assert_frame_equal
  from finmarketpy.economics.techindicator import TechParams, TechIndicator
label_desc: Use image node_id 3 for calling a global function with example usage: test_roc() without return types