Skip to content

Instantly share code, notes, and snippets.

@pdabrowski6
Created March 6, 2012 13:30
Show Gist options
  • Save pdabrowski6/1986280 to your computer and use it in GitHub Desktop.
Save pdabrowski6/1986280 to your computer and use it in GitHub Desktop.
Próbki kodu
class Sort
attr_reader :my_array
def initialize(my_array)
@my_array = my_array
end
def switch_array(element, element2)
@my_array[element], @my_array[element2] = @my_array[element2], @my_array[element]
end
def quicksort(p, r)
if p < r then
q = array_division(p, r)
quicksort(p, q-1)
quicksort(q+1, r)
end
end
def array_division(p, r)
axis = @my_array[r]
i = p - 1
p.upto(r-1) do |j|
if @my_array[j] <= axis
i = i+1
switch_array(i, j)
end
end
switch_array(i+1, r)
return i + 1
end
end
require "sort"
describe Sort do
before(:each) do
@a = [9,3,4,5]
@sort = Sort.new(@a)
end
describe "#new" do
it "should initialize given array with the same number of elements" do
@sort.my_array.size.should == @a.size
end
end
describe "#switch_array" do
it "should switch given values that one is point to other and vice versa" do
@sort.switch_array(0, 3)
@sort.my_array[0].should == 5
@sort.my_array[3].should == 9
end
end
describe "#quicksort" do
it "should sort given array" do
@sort.quicksort(0, 3)
@sort.my_array.should == [3,4,5,9]
end
end
end
function show_childrens(parent) {
$(".category-childs").each(function () {
$(this).hide();
});
if(parent != 0) {
$("#childs-of-" + parent).show();
}
}
function set_subcategory(id) {
$(".category-childs").each(function(){
var element_stay = "childs-of-" + id;
if($(this).attr("id") != element_stay) {
$(this).remove();
}
})
}
function message_check_all(status) {
$(".message-check").each( function() {
$(this).attr("checked",status);
});
}
function message_checked(root_url) {
var linki = ""
$(".message-check").each( function(){
if($(this).attr("checked") == "checked") {
linki = linki + $(this).attr("value") + ", ";
}
});
var root = root_url + "/messages/" + linki;
$("#delete-message").attr("href", root);
}
require 'spec_helper'
describe Category do
before(:each) do
@category = Category.new
end
it "should not be valid without name" do
@category.should_not be_valid
@category.errors.include?(:name).should == true
end
it "should be valid with name" do
@category.name = "test"
@category.should be_valid
@category.errors.size.should == 0
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment