<commit_before>require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
require 'set'

describe "Souffle::System" do
  before(:each) do
    @system = Souffle::System.new
  end

  after(:each) do
    @system = nil
  end

  it "should be able to initialize a Vagrant provider" do
    @system.provider.name.should eql("Vagrant")
  end

  it "should be able to initialize an AWS provider" do
    @system = Souffle::System.new("AWS")
    @system.provider.name.should eql("AWS")
  end

  it "should be able to setup an Vagrant provider" do
    @system = Souffle::System.new("Vagrant")
    @system.setup_provider
  end

  it "should be able to setup an AWS provider" do
    @system = Souffle::System.new("AWS")
    @system.setup_provider
  end

  it "raises an InvalidProvider error when the provider doesn't exist" do
    d = lambda { @system = Souffle::System.new("UnholyProviderOfBadness") }
    d.should raise_error
  end

  it "should be able to find all of the nodes with no parents" do
    node1 = Souffle::Node.new
    node2 = Souffle::Node.new
    node3 = Souffle::Node.new
    node4 = Souffle::Node.new

    node1.dependencies << "role[awesomeone]"
    node2.dependencies << "recipe[bleh]"

    @system.add(node1)
    @system.add(node2)
    @system.add(node3)
    @system.add(node4)

    @system.roots.to_set.should eql(Set.new([node3, node4]))
  end

  it "should be able to add a root node" do
    node = Souffle::Node.new
    @system.add(node)
    @system.roots.should eql([node])
  end

  it "should be able to determine dependant nodes" do
    node1 = Souffle::Node.new
    node2 = Souffle::Node.new

    node1.run_list     << "role[some_silly_role]"
    node2.dependencies << "role[some_silly_role]"

    @system.add(node1)
    @system.add(node2)

    lambda { @system.rebalance_nodes }.should_not raise_error
    @system.dependent_nodes.should eql([node2])
  end

  it "should be able to clear all nodes parent and child heirarchy" do
    node1  = Souffle::Node.new
    node2 = Souffle::Node.new

    node1.run_list     << "role[some_silly_role]"
    node2.dependencies << "role[some_silly_role]"

    @system.add(node1)
    @system.add(node2)
    @system.rebalance_nodes

    node1.children.include?(node2).should eql(true)
    node2.parents.include?(node1).should eql(true)

    @system.clear_node_heirarchy
    node1.children.should eql([])
    node2.parents.should eql([])
  end

  it "should be able to get the node dependencies on a system" do
    node1  = Souffle::Node.new
    node2 = Souffle::Node.new
    node3 = Souffle::Node.new
<commit_msg>Removed lambda that potentially would cause confusion<commit_after>require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
require 'set'

describe "Souffle::System" do
  before(:each) do
    @system = Souffle::System.new
  end

  after(:each) do
    @system = nil
  end

  it "should be able to initialize a Vagrant provider" do
    @system.provider.name.should eql("Vagrant")
  end

  it "should be able to initialize an AWS provider" do
    @system = Souffle::System.new("AWS")
    @system.provider.name.should eql("AWS")
  end

  it "should be able to setup an Vagrant provider" do
    @system = Souffle::System.new("Vagrant")
    @system.setup_provider
  end

  it "should be able to setup an AWS provider" do
    @system = Souffle::System.new("AWS")
    @system.setup_provider
  end

  it "raises an InvalidProvider error when the provider doesn't exist" do
    d = lambda { @system = Souffle::System.new("UnholyProviderOfBadness") }
    d.should raise_error
  end

  it "should be able to find all of the nodes with no parents" do
    node1 = Souffle::Node.new
    node2 = Souffle::Node.new
    node3 = Souffle::Node.new
    node4 = Souffle::Node.new

    node1.dependencies << "role[awesomeone]"
    node2.dependencies << "recipe[bleh]"

    @system.add(node1)
    @system.add(node2)
    @system.add(node3)
    @system.add(node4)

    @system.roots.to_set.should eql(Set.new([node3, node4]))
  end

  it "should be able to add a root node" do
    node = Souffle::Node.new
    @system.add(node)
    @system.roots.should eql([node])
  end

  it "should be able to determine dependant nodes" do
    node1 = Souffle::Node.new
    node2 = Souffle::Node.new

    node1.run_list     << "role[some_silly_role]"
    node2.dependencies << "role[some_silly_role]"

    @system.add(node1)
    @system.add(node2)

    @system.rebalance_nodes
    @system.dependent_nodes.should eql([node2])
  end

  it "should be able to clear all nodes parent and child heirarchy" do
    node1  = Souffle::Node.new
    node2 = Souffle::Node.new

    node1.run_list     << "role[some_silly_role]"
    node2.dependencies << "role[some_silly_role]"

    @system.add(node1)
    @system.add(node2)
    @system.rebalance_nodes

    node1.children.include?(node2).should eql(true)
    node2.parents.include?(node1).should eql(true)

    @system.clear_node_heirarchy
    node1.children.should eql([])
    node2.parents.should eql([])
  end

  it "should be able to get the node dependencies on a system" do
    node1  = Souffle::Node.new
    node2 = Souffle::Node.new
    node3 = Souffle::Node.new

{'fraction_non_alphanumeric': 0.11669902912621359, 'fraction_numerical': 0.01320388349514563, 'mean_word_length': 3.3875638841567293, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 3, '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': '6231840', 'n_tokens_mistral': 1852, 'n_tokens_neox': 1783, 'n_words': 445}