JacobNinja / exercism-analysis

2 stars 2 forks source link

Not triggering "indentation/inconsistent_spacing" rule #7

Open kytrinyx opened 9 years ago

kytrinyx commented 9 years ago

I saw the following submission today, which didn't trigger the inconsistent indentation rule. Notice how the indentation is variously 1, 2, and 4 spaces.

class Hamming
  def self.compute(first_sequence, second_sequence)
    hamming_counter = 0
    unless first_sequence.length != second_sequence.length
        split_first_sequence = first_sequence.split('')
        split_second_sequence = second_sequence.split('')
        split_first_sequence.select.with_index do |first_sequence_base,index|
          hamming_counter += 1 if first_sequence_base != split_second_sequence[index]
        end
         hamming_counter

    end
  end
end

Here's the curl call:

curl -XPOST 'http://analysseur.exercism.io/analyze/ruby' --data '{"code":"class Hamming\n  def self.compute(first_sequence, second_sequence)\n    hamming_counter = 0\n    unless first_sequence.length != second_sequence.length\n        split_first_sequence = first_sequence.split(\"\")\n        split_second_sequence = second_sequence.split(\"\")\n        split_first_sequence.select.with_index do |first_sequence_base,index|\n          hamming_counter += 1 if first_sequence_base != split_second_sequence[index]\n        end\n         hamming_counter\n\n    end"}' -H "Content-Type: application/json"
kytrinyx commented 9 years ago

Here's another example of inconsistent indentation that I would expect to trigger the rule:

class Hamming

  def self.compute(a,b)
    biggerList = []
    smallerList = []

    #detect which string is longer and split into arrays.
    if a.length > b.length
        bigger_list = a.chars
        smaller_list = b.chars
    else
        bigger_list = b.chars
        smaller_list = a.chars
    end

    #iterate over smaller array and check against larger array
    smaller_list.zip(bigger_list).count {|y, z| y != z }

    end
end
kytrinyx commented 9 years ago

Here's one more:

class Hamming
  def self.compute(strand1, strand2)
    count = 0
    if strand1.length == strand2.length
    strand1.length.times { |x| count += 1 unless strand1[x] == strand2[x]}
    end
    count
  end
end

And as a string to make it easier to use in a test:

"class Hamming\n def self.compute(strand1, strand2)\n count = 0\n if strand1.length == strand2.length\n strand1.length.times { |x| count += 1 unless strand1[x] == strand2[x]}\n end\n count\n end\nend"

kytrinyx commented 9 years ago

I found another one...

class Hamming

  class << self
    def compute(a,b)
    return -1 if a.length != b.length
      d = 0
      (a.length).times do |i|
        d+=1 if a[i] != b[i]
      end
      d
    end
  end
end
kytrinyx commented 9 years ago

I saw another one today:

class Hamming
  def self.compute(sequence1,sequence2)
    if sequence1.length != sequence2.length
      puts "ValueError, cannot calculate hamming distance for sequences of different length!"
    else
      @distance = 0
      hamming_pairs = sequence1.split('').zip(sequence2.split(''))
      hamming_pairs.each do |pair|
        @distance += 1 if pair[0] != pair[1]
      end
        @distance
    end
  end
end
JacobNinja commented 9 years ago

Howdy Katrina,

I've been out of town but I'm now actively working on this. The current rule only looks for inconsistent endings of expressions with block-like syntax. It disregards the indentation of the body. I've got a few ideas on how to solve this but it's a bit tricky to generalize the rule due to nasty edge cases. I'm experimenting with a solution that should solve all of these cases. I'll post back with my findings.

kytrinyx commented 9 years ago

Yeah, if it's nasty then let's be more conservative. I'd rather rikki- be correct than aggressive :)