code: def test_design():
      # Check that you get the design matrix we expect
      t1 = F.Term("x")
      t2 = F.Term("y")
  
      n = F.make_recarray([2, 4, 5], "x")
      assert_almost_equal(t1.formula.design(n)["x"], n["x"])
  
      f = t1.formula + t2.formula
      n = F.make_recarray([(2, 3), (4, 5), (5, 6)], "xy")
  
      assert_almost_equal(f.design(n)["x"], n["x"])
      assert_almost_equal(f.design(n)["y"], n["y"])
  
      f = t1.formula + t2.formula + F.I + t1.formula * t2.formula
      assert_almost_equal(f.design(n)["x"], n["x"])
      assert_almost_equal(f.design(n)["y"], n["y"])
      assert_almost_equal(f.design(n)["1"], 1)
      assert_almost_equal(f.design(n)["x*y"], n["x"] * n["y"])
      # drop x field, check that design raises error
      ny = np.recarray(n.shape, dtype=[("x", n.dtype["x"])])
      ny["x"] = n["x"]
      pytest.raises(ValueError, f.design, ny)
      n = np.array(
          [(2, 3, "a"), (4, 5, "b"), (5, 6, "a")],
          np.dtype([("x", np.float64), ("y", np.float64), ("f", "S1")]),
      )
      f = F.Factor("f", ["a", "b"])
      ff = t1.formula * f + F.I
      assert_almost_equal(ff.design(n)["f_a*x"], n["x"] * [1, 0, 1])
      assert_almost_equal(ff.design(n)["f_b*x"], n["x"] * [0, 1, 0])
      assert_almost_equal(ff.design(n)["1"], 1)
  
imports: from warnings import catch_warnings, simplefilter
  import numpy
  import pytest
  import sympy
  from numpy.core.records import fromrecords
  from numpy.testing import assert_almost_equal, assert_array_equal
  from sympy.utilities.lambdify import implemented_function
  from nipy.utils import VisibleDeprecationWarning
  from ..None import formulae
  from ..formulae import Term, terms
label_desc: Use image node_id 16 for calling a global function with example usage: test_design() without return types