code: def test_gen_design():
      from brainiak.utils.utils import gen_design
      import numpy as np
      import os.path
  
      files = {
          "FSL1": "example_stimtime_1_FSL.txt",
          "FSL2": "example_stimtime_2_FSL.txt",
          "AFNI1": "example_stimtime_1_AFNI.txt",
          "AFNI2": "example_stimtime_2_AFNI.txt",
      }
      for key in files.keys():
          files[key] = os.path.join(
              os.path.dirname(__file__), files[key]
          )
      design1 = gen_design(
          stimtime_files=files["FSL1"],
          scan_duration=[48, 20],
          TR=2,
          style="FSL",
      )
      assert design1.shape == (
          34,
          1,
      ), "Returned design matrix has wrong shape"
      assert design1[24] == 0, (
          "gen_design should generated design matrix for each run separately "
          "and concatenate them."
      )
      design2 = gen_design(
          stimtime_files=[files["FSL1"], files["FSL2"]],
          scan_duration=[48, 20],
          TR=2,
          style="FSL",
      )
      assert design2.shape == (
          34,
          2,
      ), "Returned design matrix has wrong shape"
      design3 = gen_design(
          stimtime_files=files["FSL1"],
          scan_duration=68,
          TR=2,
          style="FSL",
      )
      assert (
          design3[24] != 0
      ), "design matrix should be non-zero 8 seconds after an event onset."
      design4 = gen_design(
          stimtime_files=[files["FSL2"]],
          scan_duration=[48, 20],
          TR=2,
          style="FSL",
      )
      assert np.all(
          np.isclose(design1 * 0.5, design4)
      ), "gen_design does not treat missing values correctly"
      design5 = gen_design(
          stimtime_files=[files["FSL2"]], scan_duration=[48, 20], TR=1
      )
      assert (np.abs(design4 - design5[::2])).mean() < 0.1, (
          "design matrices sampled at different frequency do not match"
          " at corresponding time points"
      )
      design6 = gen_design(
          stimtime_files=[files["AFNI1"]],
          scan_duration=[48, 20],
          TR=2,
          style="AFNI",
      )
      assert np.all(
          np.isclose(design1, design6)
      ), "design matrices generated from AFNI style and FSL style do not match"
      design7 = gen_design(
          stimtime_files=[files["AFNI2"]],
          scan_duration=[48],
          TR=2,
          style="AFNI",
      )
      assert np.all(design7 == 0.0), (
          "A negative stimulus onset of AFNI style should result in an all-zero"
          + " design matrix"
      )
  
file_path: brainiak/tests/utils/test_utils.py
imports: import pytest
label_desc: Use image node_id 6 for calling a global function with example usage: test_gen_design() without return types