Skip to content

Commit

Permalink
Merge pull request #2890 from nicolossus/port_test_spike_recorder
Browse files Browse the repository at this point in the history
Port `test_spike_recorder` from SLI-2-Py
  • Loading branch information
heplesser authored Aug 15, 2023
2 parents 0bc8967 + 850346a commit f261d65
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 78 deletions.
58 changes: 58 additions & 0 deletions testsuite/pytests/sli2py_recording/test_spike_recorder.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# -*- coding: utf-8 -*-
#
# test_spike_recorder.py
#
# This file is part of NEST.
#
# Copyright (C) 2004 The NEST Initiative
#
# NEST is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 2 of the License, or
# (at your option) any later version.
#
# NEST is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with NEST. If not, see <http://www.gnu.org/licenses/>.

"""
Test that ``spike_recorder`` behaves as expected.
"""

import nest
import numpy.testing as nptest
import pytest


def simulator(resolution):
"""
Simulate the system with provided time resolution and return spike times.
"""

nest.ResetKernel()
nest.resolution = resolution

spike_times = [0.1, 5.0, 5.3, 5.33, 5.4, 5.9, 6.0]

sgen = nest.Create("spike_generator", params={"spike_times": spike_times, "precise_times": True})
srec = nest.Create("spike_recorder")

nest.Connect(sgen, srec)

nest.Simulate(8.0)

return srec.events["times"], spike_times


@pytest.mark.parametrize("resolution", [1.0, 0.1, 0.02, 0.01, 0.001])
def test_spike_recorder_different_resolutions(resolution):
"""
Test that recorded spike times are independent of resolution.
"""

actual_spikes, expected_spikes = simulator(resolution)
nptest.assert_almost_equal(actual_spikes, expected_spikes)
78 changes: 0 additions & 78 deletions testsuite/unittests/test_spike_recorder.sli

This file was deleted.

0 comments on commit f261d65

Please sign in to comment.