Skip to content

Commit

Permalink
replace rspec with minitest
Browse files Browse the repository at this point in the history
  • Loading branch information
tonytonyjan committed Dec 11, 2015
1 parent c46d208 commit accc6eb
Show file tree
Hide file tree
Showing 7 changed files with 92 additions and 184 deletions.
23 changes: 14 additions & 9 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
require "bundler/gem_tasks"
require "rake/extensiontask"
require 'rspec/core/rake_task'
require 'bundler/gem_tasks'
require 'rake/extensiontask'
require 'rake/testtask'

RSpec::Core::RakeTask.new(:spec)
Rake::ExtensionTask.new("jaro_winkler") do |ext|
ext.lib_dir = "lib/jaro_winkler"
end

task default: [:compile, :spec]
task default: [:compile, :test]

task benchmark: %w[benchmark:native benchmark:pure]

Expand Down Expand Up @@ -52,4 +47,14 @@ task compare: :compile do
end
end
table.each{|row| puts row.join(' | ')}
end

Rake::ExtensionTask.new('jaro_winkler') do |ext|
ext.lib_dir = 'lib/jaro_winkler'
end

Rake::TestTask.new do |t|
t.libs << 'test'
t.test_files = FileList['test/**/test_*.rb']
t.verbose = true
end
9 changes: 7 additions & 2 deletions ext/jaro_winkler/jaro_winkler.c
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
#include "ruby.h"
#include "jaro.h"

VALUE rb_mJaroWinkler;
VALUE rb_mJaroWinkler,
rb_eError,
rb_eInvalidWeightError;

VALUE distance(int argc, VALUE *argv, VALUE self);

void Init_jaro_winkler(void){
rb_mJaroWinkler = rb_define_module("JaroWinkler");
rb_eError = rb_define_class_under(rb_mJaroWinkler, "Error", rb_eRuntimeError);
rb_eInvalidWeightError = rb_define_class_under(rb_mJaroWinkler, "InvalidWeightError", rb_eError);
rb_define_module_function(rb_mJaroWinkler, "c_distance", distance, -1);
}

Expand All @@ -19,7 +24,7 @@ VALUE distance(int argc, VALUE *argv, VALUE self){
ignore_case = rb_hash_aref(opt, ID2SYM(rb_intern("ignore_case"))),
adj_table = rb_hash_aref(opt, ID2SYM(rb_intern("adj_table")));
if(!NIL_P(weight)) c_opt.weight = NUM2DBL(weight);
if(c_opt.weight > 0.25) rb_raise(rb_eRuntimeError, "Scaling factor should not exceed 0.25, otherwise the distance can become larger than 1.");
if(c_opt.weight > 0.25) rb_raise(rb_eInvalidWeightError, "Scaling factor should not exceed 0.25, otherwise the distance can become larger than 1.");
if(!NIL_P(threshold)) c_opt.threshold = NUM2DBL(threshold);
if(!NIL_P(ignore_case)) c_opt.ignore_case = (TYPE(ignore_case) == T_FALSE || NIL_P(ignore_case)) ? 0 : 1;
if(!NIL_P(adj_table)) c_opt.adj_table = (TYPE(adj_table) == T_FALSE || NIL_P(adj_table)) ? 0 : 1;
Expand Down
2 changes: 1 addition & 1 deletion jaro_winkler.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Gem::Specification.new do |spec|
spec.add_development_dependency "bundler", "~> 1.7"
spec.add_development_dependency "rake", "~> 10.0"
spec.add_development_dependency "rake-compiler"
spec.add_development_dependency "rspec"
spec.add_development_dependency "minitest"
spec.add_development_dependency "fuzzy-string-match"
spec.add_development_dependency "hotwater"
spec.add_development_dependency "amatch"
Expand Down
8 changes: 0 additions & 8 deletions spec/adjusting_table_spec.rb

This file was deleted.

75 changes: 0 additions & 75 deletions spec/jaro_winkler_spec.rb

This file was deleted.

89 changes: 0 additions & 89 deletions spec/spec_helper.rb

This file was deleted.

70 changes: 70 additions & 0 deletions test/test_jaro_winkler.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
require 'minitest/autorun'
require 'jaro_winkler'

class TestJaroWinkler < Minitest::Test
def test_distance
assert_distance 0.9667, 'henka', 'henkan'
assert_distance 1.0, 'al', 'al'
assert_distance 0.9611, 'martha', 'marhta'
assert_distance 0.8324, 'jones', 'johnson'
assert_distance 0.9583, 'abcvwxyz', 'cabvwxyz'
assert_distance 0.8400, 'dwayne', 'duane'
assert_distance 0.8133, 'dixon', 'dicksonx'
assert_distance 0.0, 'fvie', 'ten'
assert_distance 1.0, 'tony', 'tony'
assert_distance 1.0, 'tonytonyjan', 'tonytonyjan'
assert_distance 1.0, 'x', 'x'
assert_distance 0.0, '', ''
assert_distance 0.0, 'tony', ''
assert_distance 0.0, '', 'tony'
assert_distance 0.8727, 'tonytonyjan', 'tony'
assert_distance 0.8727, 'tony', 'tonytonyjan'
end

def test_unicode
assert_distance 0.9818, '變形金剛4:絕跡重生', '變形金剛4: 絕跡重生'
assert_distance 0.8222, '連勝文', '連勝丼'
assert_distance 0.8222, '馬英九', '馬英丸'
assert_distance 0.6667, '良い', 'いい'
end

def test_ignore_case
assert_distance 0.9611, 'MARTHA', 'marhta', ignore_case: true
end

def test_weight
assert_distance 0.9778, 'MARTHA', 'MARHTA', weight: 0.2
end

def test_threshold
assert_distance 0.9444, 'MARTHA', 'MARHTA', threshold: 0.99
end


def test_adjusting_table
assert_distance 0.9667, 'HENKA', 'HENKAN', adj_table: true
assert_distance 1.0, 'AL', 'AL', adj_table: true
assert_distance 0.9611, 'MARTHA', 'MARHTA', adj_table: true
assert_distance 0.8598, 'JONES', 'JOHNSON', adj_table: true
assert_distance 0.9583, 'ABCVWXYZ', 'CABVWXYZ', adj_table: true
assert_distance 0.8730, 'DWAYNE', 'DUANE', adj_table: true
assert_distance 0.8393, 'DIXON', 'DICKSONX', adj_table: true
assert_distance 0.0, 'FVIE', 'TEN', adj_table: true
end

def test_error
assert_raises JaroWinkler::InvalidWeightError do
JaroWinkler.distance 'MARTHA', 'MARHTA', weight: 0.26
end
end

def test_long_string
JaroWinkler.distance 'haisai' * 20, 'haisai' * 20
end

private

def assert_distance score, str1, str2, **options
assert_equal score, JaroWinkler.distance(str1, str2, **options).round(4)
end
end

0 comments on commit accc6eb

Please sign in to comment.