<commit_before>require 'spec_helper'

def data_set
  {
    "a Hash" => [{ :foo => :bar }],
    "a String" => ["Woof!"],
    "an Array" => [[1, 2, 3]],
    "a stream of packets" => [{ :foo => :bar }, "Woof!", [1, 2, 3]],
    "huge packet" => [[:frogspawn] * 1000],
    "100 small packets" => 100.times.map { rand(100000) },
  }
end

module Chingu
  describe "Network" do
    
    describe Chingu::GameStates::NetworkServer do
      it "should open listening port on start()" do
        @server = described_class.new(:ip => "0.0.0.0", :port => 9999)
        @server.should_receive(:on_start)
        @server.start
        @server.stop
      end

      it "should call on_start_error() if failing" do
        @server = described_class.new(:ip => "1.2.3.999", :port => 12345678) # crazy ip:port
        @server.should_receive(:on_start_error)
        @server.start
        @server.stop
      end
<commit_msg>client connection test to dead ip<commit_after>require 'spec_helper'

def data_set
  {
    "a Hash" => [{ :foo => :bar }],
    "a String" => ["Woof!"],
    "an Array" => [[1, 2, 3]],
    "a stream of packets" => [{ :foo => :bar }, "Woof!", [1, 2, 3]],
    "huge packet" => [[:frogspawn] * 1000],
    "100 small packets" => 100.times.map { rand(100000) },
  }
end

module Chingu
  describe "Network" do
    
    describe Chingu::GameStates::NetworkServer do
      it "should open listening port on start()" do
        @server = described_class.new(:ip => "0.0.0.0", :port => 9999)
        @server.should_receive(:on_start)
        @server.start
        @server.stop
      end

      it "client should timeout when connecting to blackhole ip" do
        @client = Chingu::GameStates::NetworkClient.new(:ip => "192.168.3.11", :port => 1234, :debug => true)
        @client.connect
        
        #@client.should_receive(:on_timeout) ## gives on_connection_refused instead, kind of ok.
        @client.should_receive(:on_connection_refused)
        @client.update while @client.socket
      end

      it "should call on_start_error() if failing" do
        @server = described_class.new(:ip => "1.2.3.999", :port => 12345678) # crazy ip:port
        @server.should_receive(:on_start_error)
        @server.start
        @server.stop
      end

{'fraction_non_alphanumeric': 0.15761353517364202, 'fraction_numerical': 0.044968833481745324, 'mean_word_length': 2.6775777414075286, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 30, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 5, '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': '5080577', 'n_tokens_mistral': 824, 'n_tokens_neox': 742, 'n_words': 193}