function gT(name) {
  return document.getElementsByTagName(name)
}

function gTF(name) {
  return gT(name)[0]
}

function g(value) {
  return document.getElementById(value)
}

function matchGetBoundingClientRectAll(element, value) {
  var x = element.getBoundingClientRect(),
      pass = x.top == value[0] && x.right == value[1] && x.bottom == value[2] && x.left == value[3]
  return [pass, (!pass) ? "Expected: " + value + ". Got: " + [x.top, x.right, x.bottom, x.left] + "." : ""]
}

function r(n) {
  return Math.round(n)
}

function roundArray(a) {
  for(x in a)
    a[x] = r(a[x])
  return a
}

function numberMatch(n1, n2) {
  return r(n1) == n2
}

function matchGetClientRectsAll(element, value) {
  var x = element.getClientRects(),
      temp = false,
      results = []
      pass = false
  if(value.length != x.length)
    return [pass, "Expected amount of rectangles: " + value.length + ". Got: " + x.length + "."]
  pass = true
  for(var i = 0; i < value.length; i++) {
    temp = numberMatch(x[i].top, value[i][0]) && numberMatch(x[i].right, value[i][1]) && numberMatch(x[i].bottom, value[i][2]) && numberMatch(x[i].left, value[i][3])
    results.push(roundArray([x[i].top, x[i].right, x[i].bottom, x[i].left]))
    if(!temp)
      pass = false
  }
  return [pass, (!pass) ? "Expected: " + value + ". Got: " + results + "." : ""]
}

function testRects(target, expected, result) {
  var res = matchGetClientRectsAll(target, expected),
      pass = res[0]
  result.firstChild.data = pass ? "PASS" : "FAIL. " + res[1]
}

function testRectsById(targetId, expected, resultId) {
  testRects(g(targetId), expected, g(resultId))
}

function testRect(target, expected, result) {
  var res = matchGetBoundingClientRectAll(target, expected),
      pass = res[0]
  result.firstChild.data = pass ? "PASS" : "FAIL. " + res[1]
}

function testRectById(targetId, expected, resultId) {
  testRect(g(targetId), expected, g(resultId))
}
