# -*- coding: utf-8 -*- require File.dirname(__FILE__) + '/../../spec_helper' describe Kmeans::HCluster do before :all do @blognames = ["The Superficial - Because You're Ugly", "Wonkette", "Publishing 2.0"] @data = [[0, 1, 0, 0, 3, 3, 0, 0, 3, 0, 6, 0, 1, 0, 4, 3, 0, 0, 0, 0, 0, 4, 0, 0, 1, 1, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 3, 0, 2, 0, 1, 1, 0, 0, 0, 0, 0, 5, 0, 0, 0, 0, 0, 1, 0, 0, 2, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 4, 0, 0, 0, 2, 0, 2, 0, 0, 0, 1, 3, 0, 0, 2, 0, 0, 0, 0, 0, 0, 1, 5, 1, 0, 0, 3, 0, 0, 0, 0, 1, 5, 0, 0, 2, 1, 0, 1, 2, 1, 0, 0, 0, 5, 0, 3, 0, 0, 0, 1, 0, 2, 2, 0, 3, 0, 1, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 3, 1, 0, 0, 4, 0, 1, 0, 1, 0, 0, 2, 2, 2, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 2, 0, 0, 0, 3, 0, 2, 1, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 2, 2, 0, 0, 0, 0, 0, 0, 0, 2, 1, 1, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 2, 1, 2, 0, 0, 0, 0, 4, 4, 0, 0, 0, 0, 0, 21, 2, 0, 0, 0, 0, 0, 0, 4, 0, 0, 0, 5, 0, 1, 0, 0, 2, 0, 0, 0, 0, 3, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 3,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, 4, 0, 0, 0, 1, 0, 0, 0, 1, 0, 4, 0, 4, 2, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 1, 0, 6, 0, 0, 1, 2, 0, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 0, 2, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 1, 11, 0, 0, 0, 0, 1, 1, 2, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 4, 0, 0, 0, 3, 1, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 1, 4, 0, 0, 0, 0, 0, 0]] end context 'の HCluster クラスにおいて' do describe '二次元配列を渡すと' do it "Kmeans::Bicluster クラスが返却される" do cs = Kmeans::HCluster.new clust = cs.hcluster(@data) clust.class.should == Kmeans::Bicluster end end end context 'の HCluster クラスにおいて' do describe 'printclust メソッドを呼ぶと' do it "クラスタの中身が返却される" do cs = Kmeans::HCluster.new clust = cs.hcluster(@data) out = cs.printclust(clust, @blognames) out.should == "- Wonkette - The Superficial - Because You're Ugly Publishing 2.0 " end end end end