Skip to content

Instantly share code, notes, and snippets.

@diegocasmo
Last active March 6, 2017 19:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save diegocasmo/4a9d1f91e07d0344e06e4ecf0f90cd86 to your computer and use it in GitHub Desktop.
Save diegocasmo/4a9d1f91e07d0344e06e4ecf0f90cd86 to your computer and use it in GitHub Desktop.
Tests for the implementation of the 'The Fast Fourier Transform Algorithm'
require 'minitest/autorun'
require './fft'
describe FFT do
before do
@fft = FFT.new
end
describe "#fft" do
it "should return a point-wise representation of a polynomial of degree 1" do
assert_equal(@fft.fft([1, 1]), [
Complex(2, +0),
Complex(0.0, -1.2246467991473532e-16)
])
end
it "should return a point-wise representation of a polynomial of degree 3" do
assert_equal(@fft.fft([1, 1, 0, 0]), [
Complex(2, +0),
Complex(1.0, -1.0),
Complex(0.0, -1.2246467991473532e-16),
Complex(0.9999999999999998, +1.0)
])
end
it "should return a point-wise representation of a polynomial of degree 7" do
assert_equal(@fft.fft([1, 1, 1, 1, 0, 0, 0, 0]), [
Complex(4, +0),
Complex(1.0, -2.414213562373095),
Complex(-1.2246467991473532e-16, -1.2246467991473532e-16),
Complex(1.0, -0.4142135623730949),
Complex(0.0, -2.4492935982947064e-16),
Complex(0.9999999999999998, +0.41421356237309515),
Complex(1.2246467991473532e-16, -1.224646799147353e-16),
Complex(0.9999999999999994, +2.414213562373095)
])
end
end
end
@diegocasmo
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment