<commit_before>require 'spec_helper'

module Marty::DataGridSpec
  describe DataGrid do

G1 =<<EOS
state\tstring\tv\t\t
ltv\tnumrange\tv\t\t
fico\tnumrange\th\t\t

\t\t>=600<700\t>=700<750\t>=750
CA\t<=80\t1.1\t2.2\t3.3
TX|HI\t>80<=105\t4.4\t5.5\t6.6
NM\t<=80\t1.2\t2.3\t3.4
MA\t>80<=105\t4.5\t5.6\t
\t<=80\t11\t22\t33
EOS

G2 =<<EOS
units\tinteger\tv\t\t
ltv\tnumrange\tv\t\t
cltv\tnumrange\th\t\t
fico\tnumrange\th\t\t

\t\t>=100<110\t>=110<120\t>=120
\t\t>=600<700\t>=700<750\t>=750
1|2\t<=80\t1.1\t2.2\t3.3
1|2\t>80<=105\t4.4\t5.5\t6.6
3|4\t<=80\t1.2\t2.3\t3.4
3|4\t>80<=105\t4.5\t5.6\t6.7
EOS

G3 = File.open(File.expand_path("../srp_data.csv", __FILE__)).read

G4 =<<EOS
lenient
hb_indicator\tboolean\tv
cltv\tnumrange\th

\t<=60\t>60<=70\t>70<=75\t>75<=80\t>80<=85\t>85<=90\t>90<=95\t>95<=97
true\t-0.750\t-0.750\t-0.750\t-1.500\t-1.500\t-1.500\t\t
EOS

G5 =<<EOS
ltv\tnumrange\tv\t\t

<=115\t-0.375
>115<=135\t-0.750
EOS

G6 =<<EOS
ltv\tnumrange\th

<=115\t>115<=135
-0.375\t-0.750
EOS

G7 =<<EOS
string
hb_indicator\tboolean\tv
cltv\tnumrange\th

\t<=60\t>60<=70\t>70<=75\t>75<=80\t>80<=85\t>85<=90\t>90<=95\t>95<=97
true\tThis\tis\ta\ttest\tof\tstring type\t\t
EOS

G8 =<<EOS
Marty::DataGrid
ltv\tnumrange\tv\t\t

<=115\tG1
>115<=135\tG2
>135<=140\tG3
EOS

G9 =<<EOS
state\tstring\tv
ltv\tnumrange\tv

CA|TX\t>80\t123
\t>80\t456
EOS

Ga =<<EOS
dg\tMarty::DataGrid\tv\t\t

G1|G2\t7
G3\t8
EOS

Gb =<<EOS
property_state\tGemini::State\tv\t\t

CA|TX\t70
GA\t80
MN\t90
EOS

Gc =<<EOS
Marty::DataGrid
property_state\tGemini::State\tv\t\t

CA|TX\tGb
EOS

Gd =<<EOS
hb_indicator\tboolean\tv

true\t456
false\t123
EOS

Ge =<<EOS
ltv\tnumrange\th

>110\t>120
1.1\t1.1
EOS

Gf = <<EOS
lenient string
b\tboolean\tv
i\tinteger\tv
i4\tint4range\tv
n\tnumrange\tv

true\t1\t<10\t<10.0\tY
\t2\t\t\tM
false\t\t>10\t\tN
EOS

Gg = <<EOS
lenient
i1\tinteger\tv
i2\tinteger\tv

\t1\t1
2\t1\t21
2\t\t20
EOS

Gh =<<EOS
units\tinteger\tv\t\t
ltv\tfloat\tv\t\t
cltv\tfloat\th\t\t
fico\tnumrange\th\t\t

\t\t80.5\t90.5\t100.5
\t\t>=600<700\t>=700<750\t>=750
1|2\t80.5\t1.1\t2.2\t3.3
1|2\t90.5\t4.4\t5.5\t6.6
3|4\t100.5\t1.2\t2.3\t3.4
3|4\t105.5\t4.5\t5.6\t6.7
EOS


    before(:each) do
      #Mcfly.whodunnit = Marty::User.find_by_login('marty')
      marty_whodunnit
    end

    def lookup_grid_helper(pt, gridname, params, follow=false)
      dg=Marty::DataGrid.lookup(pt, gridname)
      res=dg.lookup_grid_distinct_entry(pt, params, nil, follow)
      [res["result"], res["name"]]
    end

    describe "validations" do
      it "a basic data grid should load ok" do
        dg_from_import("G1", G1)
        dg_from_import("G2", G2)
        dg_from_import("G3", G3)
        dg_from_import("G8", G8)
        dg_from_import("Ga", Ga)

        expect(Marty::DataGrid.lookup('infinity', "G1").name).to eq "G1"
        expect(Marty::DataGrid.lookup('infinity', "G2").name).to eq "G2"
        expect(Marty::DataGrid.lookup('infinity', "G3").name).to eq "G3"
      end

      it "should not allow bad axis types" do
        expect {
          dg_from_import("Gh", Gh)
        }.to raise_error(/unknown metadata type float/)
        expect {
          dg_from_import("Gh", Gh.sub(/float/, 'abcdef'))
        }.to raise_error(/unknown metadata type abcdef/)
      end

      it "should not allow dup attr names" do
        g_bad = G1.sub(/fico/, "ltv")

        expect {
          dg_from_import("G2", g_bad)
        }.to raise_error(ActiveRecord::RecordInvalid)
      end

      it "should not allow dup grid names" do<commit_msg>rename test grid -- name used in another commit<commit_after>require 'spec_helper'

module Marty::DataGridSpec
  describe DataGrid do

G1 =<<EOS
state\tstring\tv\t\t
ltv\tnumrange\tv\t\t
fico\tnumrange\th\t\t

\t\t>=600<700\t>=700<750\t>=750
CA\t<=80\t1.1\t2.2\t3.3
TX|HI\t>80<=105\t4.4\t5.5\t6.6
NM\t<=80\t1.2\t2.3\t3.4
MA\t>80<=105\t4.5\t5.6\t
\t<=80\t11\t22\t33
EOS

G2 =<<EOS
units\tinteger\tv\t\t
ltv\tnumrange\tv\t\t
cltv\tnumrange\th\t\t
fico\tnumrange\th\t\t

\t\t>=100<110\t>=110<120\t>=120
\t\t>=600<700\t>=700<750\t>=750
1|2\t<=80\t1.1\t2.2\t3.3
1|2\t>80<=105\t4.4\t5.5\t6.6
3|4\t<=80\t1.2\t2.3\t3.4
3|4\t>80<=105\t4.5\t5.6\t6.7
EOS

G3 = File.open(File.expand_path("../srp_data.csv", __FILE__)).read

G4 =<<EOS
lenient
hb_indicator\tboolean\tv
cltv\tnumrange\th

\t<=60\t>60<=70\t>70<=75\t>75<=80\t>80<=85\t>85<=90\t>90<=95\t>95<=97
true\t-0.750\t-0.750\t-0.750\t-1.500\t-1.500\t-1.500\t\t
EOS

G5 =<<EOS
ltv\tnumrange\tv\t\t

<=115\t-0.375
>115<=135\t-0.750
EOS

G6 =<<EOS
ltv\tnumrange\th

<=115\t>115<=135
-0.375\t-0.750
EOS

G7 =<<EOS
string
hb_indicator\tboolean\tv
cltv\tnumrange\th

\t<=60\t>60<=70\t>70<=75\t>75<=80\t>80<=85\t>85<=90\t>90<=95\t>95<=97
true\tThis\tis\ta\ttest\tof\tstring type\t\t
EOS

G8 =<<EOS
Marty::DataGrid
ltv\tnumrange\tv\t\t

<=115\tG1
>115<=135\tG2
>135<=140\tG3
EOS

G9 =<<EOS
state\tstring\tv
ltv\tnumrange\tv

CA|TX\t>80\t123
\t>80\t456
EOS

Ga =<<EOS
dg\tMarty::DataGrid\tv\t\t

G1|G2\t7
G3\t8
EOS

Gb =<<EOS
property_state\tGemini::State\tv\t\t

CA|TX\t70
GA\t80
MN\t90
EOS

Gc =<<EOS
Marty::DataGrid
property_state\tGemini::State\tv\t\t

CA|TX\tGb
EOS

Gd =<<EOS
hb_indicator\tboolean\tv

true\t456
false\t123
EOS

Ge =<<EOS
ltv\tnumrange\th

>110\t>120
1.1\t1.1
EOS

Gf = <<EOS
lenient string
b\tboolean\tv
i\tinteger\tv
i4\tint4range\tv
n\tnumrange\tv

true\t1\t<10\t<10.0\tY
\t2\t\t\tM
false\t\t>10\t\tN
EOS

Gg = <<EOS
lenient
i1\tinteger\tv
i2\tinteger\tv

\t1\t1
2\t1\t21
2\t\t20
EOS

Gi =<<EOS
units\tinteger\tv\t\t
ltv\tfloat\tv\t\t
cltv\tfloat\th\t\t
fico\tnumrange\th\t\t

\t\t80.5\t90.5\t100.5
\t\t>=600<700\t>=700<750\t>=750
1|2\t80.5\t1.1\t2.2\t3.3
1|2\t90.5\t4.4\t5.5\t6.6
3|4\t100.5\t1.2\t2.3\t3.4
3|4\t105.5\t4.5\t5.6\t6.7
EOS

    before(:each) do
      #Mcfly.whodunnit = Marty::User.find_by_login('marty')
      marty_whodunnit
    end

    def lookup_grid_helper(pt, gridname, params, follow=false)
      dg=Marty::DataGrid.lookup(pt, gridname)
      res=dg.lookup_grid_distinct_entry(pt, params, nil, follow)
      [res["result"], res["name"]]
    end

    describe "validations" do
      it "a basic data grid should load ok" do
        dg_from_import("G1", G1)
        dg_from_import("G2", G2)
        dg_from_import("G3", G3)
        dg_from_import("G8", G8)
        dg_from_import("Ga", Ga)

        expect(Marty::DataGrid.lookup('infinity', "G1").name).to eq "G1"
        expect(Marty::DataGrid.lookup('infinity', "G2").name).to eq "G2"
        expect(Marty::DataGrid.lookup('infinity', "G3").name).to eq "G3"
      end

      it "should not allow bad axis types" do
        expect {
          dg_from_import("Gi", Gi)
        }.to raise_error(/unknown metadata type float/)
        expect {
          dg_from_import("Gi", Gi.sub(/float/, 'abcdef'))
        }.to raise_error(/unknown metadata type abcdef/)
      end

      it "should not allow dup attr names" do
        g_bad = G1.sub(/fico/, "ltv")

        expect {
          dg_from_import("G2", g_bad)
        }.to raise_error(ActiveRecord::RecordInvalid)
      end

      it "should not allow dup grid names" do
{'fraction_non_alphanumeric': 0.19866798923055123, 'fraction_numerical': 0.12073118889046337, 'mean_word_length': 2.992081447963801, 'pattern_counts': {'":': 0, '<': 151, '<?xml version=': 0, '>': 81, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '494196', 'n_tokens_mistral': 4036, 'n_tokens_neox': 3647, 'n_words': 506}