From b6820b015c1a2767916e3d894cd9cd76d67b94b9 Mon Sep 17 00:00:00 2001 From: Patrick Simianer Date: Thu, 16 Jul 2015 15:51:20 +0200 Subject: SparseVector: norm, unit --- test/test_sparsevector.rb | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100755 test/test_sparsevector.rb (limited to 'test/test_sparsevector.rb') diff --git a/test/test_sparsevector.rb b/test/test_sparsevector.rb new file mode 100755 index 0000000..a23a7d3 --- /dev/null +++ b/test/test_sparsevector.rb @@ -0,0 +1,18 @@ +#!/usr/bin/env ruby + +require_relative '../lib/zipf/SparseVector' +require 'test/unit' + +class TestSparseVector < Test::Unit::TestCase + + def test_unit + v = SparseVector.new + v[:a] = 1 + v[:b] = 2 + v[:c] = 3 + assert_equal Math.sqrt(1**2+2**2+3**2), v.norm + v.unit! + assert_equal v.norm, 1.0 + end +end + -- cgit v1.2.3