import spock.lang.Specification

class ScramblerTest extends Specification {
	def scrambler
  def FINNISH = "finnish"
  def CAE = "cae"

	def setup() {
		scrambler = new Scrambler()
	}
	
	def "canary"() {
		expect:
		  true == true
	}
	
	def "scrambled word has same length"() {
		expect:
		  scrambler.scramble(FINNISH).length() == FINNISH.length()
	}

	def "scrambled word is different"() {
		expect:
		  scrambler.scramble(FINNISH) != FINNISH
	}
	
	def "scramble word is not repeated"() {
		expect:
		  scrambler.scramble(FINNISH) != scrambler.scramble(FINNISH)
	}
	
	def "score for perfect match"() {
		expect:
		  13 == scrambler.score(CAE, "ace")
	}
	
	def "score excess characters"() {
		when:
		  scrambler.score(CAE, "aace")
		then:
		  def ex = thrown(RuntimeException)
		  ex.message == "Too many letters"
	}
	
	def "score for letter not in scrambled"() {
		expect:
		  0 == scrambler.score(FINNISH, "fan")
	}
	
	def "score 1 for letters"() {
		expect:
		  1 == scrambler.scoreForLetter(letter)
		
		where:
		  letter << ['A', 'C', 'D', 'E', 'I', 'N', 'O', 'R', 'S', 'T']
	}
	
	def "score 2 for letters"() {
		expect:
		  2 == scrambler.scoreForLetter(letter)
		
		where:
		  letter << ['G', 'H', 'L']
	}
	
	def "score 3 for letters"() {
		expect:
		  3 == scrambler.scoreForLetter(letter)
		
		where:
		  letter << ['K', 'W', 'X']
	}

	def "score 4 for letters"() {
		expect:
		  4 == scrambler.scoreForLetter(letter)
		
		where:
		  letter << ['M', 'U', 'Y']
	}

	def "score 5 for letters"() {
		expect:
		  5 == scrambler.scoreForLetter(letter)
		
		where:
		  letter << ['P', 'V', 'Z']
	}

	def "score 8 for letters"() {
		expect:
		  8 == scrambler.scoreForLetter(letter)
		
		where:
		  letter << ['B', 'F', 'Q']
	}

	def "score 10 for letters"() {
		expect:
		  10 == scrambler.scoreForLetter('J')
	}
	
	def "score for bonus"() {
		expect:
		  0 == scrambler.scoreForBonus(FINNISH, "finish")
		  10 == scrambler.scoreForBonus("fininsh", "finnish")
	}
	
	def "score for multiple words"() {
		expect:
		  score == scrambler.score(FINNISH, word)
		
		where:
		  word | score
      'fan'     | 0 		
      'fin'     | 10		
      'fish'    | 12		
      'finnish' | 25		
	}
}