text:
package quasar.mimir

import quasar.precog.common._
import quasar.yggdrasil._
import scalaz._

trait StringLibSpecs[M[+_]] extends EvaluatorSpecification[M]
    with LongIdMemoryDatasetConsumer[M] { self =>

  import dag._
  import instructions._
  import library._

  private def homStrings = dag.AbsoluteLoad(Const(CString("/hom/strings")))
  private def hetStrings = dag.AbsoluteLoad(Const(CString("/het/strings")))

  def testEval(graph: DepGraph): Set[SEvent] = {
    consumeEval(graph, defaultEvaluationContext) match {
      case Success(results) => results
      case Failure(error) => throw error
    }
  }

  def op1Input(op: Op1, loadFrom: dag.AbsoluteLoad) = {
    dag.Operate(BuiltInFunction1Op(op), loadFrom)
  }

  def op2Input(op: Op2, const: RValue, loadFrom: dag.AbsoluteLoad) = {
    Join(BuiltInFunction2Op(op), Cross(None), loadFrom, Const(const))
  }

  "for homogeneous sets, the appropriate string function" should {
    "determine length" in {
      val input = op1Input(library.length, homStrings)
      val result = testEval(input)

      result must haveSize(6)

      val result2 = result collect {
        case (ids, SDecimal(d)) if ids.length == 1 => d
      }

      result2 must contain(6, 12, 16, 26, 42, 0)
    }
    "determine trim" in {
      val input = op1Input(trim, homStrings)

      val result = testEval(input)

      result must haveSize(6)

      val result2 = result collect {
        case (ids, SString(d)) if ids.length == 1 => d
      }

      result2 must contain("quirky", "solstice + 7", "Monkey: [Brains]", """("alpha", "beta", "gamma")""", "Whitespace       is   awesome  !!!1!!", "")
    }
    "determine toUpperCase" in {
      val input = op1Input(toUpperCase, homStrings)

      val result = testEval(input)

      result must haveSize(6)

      val result2 = result collect {
        case (ids, SString(d)) if ids.length == 1 => d
      }

      result2 must contain("QUIRKY", "SOLSTICE + 7", "MONKEY: [BRAINS]", """("ALPHA", "BETA", "GAMMA")""", "  WHITESPACE       IS   AWESOME  !!!1!!   ", "")
    }
    "determine toLowerCase" in {
      val input = op1Input(toLowerCase, homStrings)

      val result = testEval(input)

      result must haveSize(6)

      val result2 = result collect {
        case (ids, SString(d)) if ids.length == 1 => d
      }

      result2 must contain("quirky", "solstice + 7", "monkey: [brains]", """("alpha", "beta", "gamma")""", "  whitespace       is   awesome  !!!1!!   ", "")
    }
    "determine isEmpty" in {
      val input = op1Input(isEmpty, homStrings)

      val result = testEval(input)

      result must haveSize(6)

      val result2 = result collect {
        case (ids, SBoolean(d)) if ids.length == 1 => d
      }

      result2 must contain(true, false)
    }
    "determine intern" in {
      val input = op1Input(intern, homStrings)

      val result = testEval(input)

      result must haveSize(6)

      val result2 = result collect {
        case (ids, SString(d)) if ids.length == 1 => d
      }

      result2 must contain("quirky", "solstice + 7", "Monkey: [Brains]", """("alpha", "beta", "gamma")""", "  Whitespace       is   awesome  !!!1!!   ", "")
    }

    "determine codePointAt with valid integer" in {
      val input = op2Input(codePointAt, CLong(7), homStrings)

      val result = testEval(input)

      result must haveSize(4)

      val result2 = result collect {
        case (ids, SDecimal(d)) if ids.length == 1 => d
      }

      result2 must contain(101, 32, 34, 115)
    }
    "determine codePointAt with invalid integer" in {
      val input = op2Input(codePointAt, CNum(7.5), homStrings)

      val result = testEval(input)

      result must haveSize(0)

      val result2 = result collect {
        case (ids, SDecimal(d)) if ids.length == 1 => d
      }

      result2 must haveSize(0)
    }
    "determine startsWith" in {
      val input = op2Input(startsWith, CString("s"), homStrings)

      val result = testEval(input)

      result must haveSize(6)

      val result2 = result collect {
        case (ids, SBoolean(d)) if ids.length == 1 => d
      }

      result2 must contain(true, false)
    }
    "determine lastIndexOf" in {
      val input = op2Input(lastIndexOf, CString("s"), homStrings)

      val result = testEval(input)

      result must haveSize(6)

      val result2 = result collect {
        case (ids, SDecimal(d)) if ids.length == 1 => d
      }

      result2 must contain(-1, 3, 14, 27)
    }
    "determine concat" in {
      val input = op2Input(concat, CString("7"), homStrings)

      val result = testEval(input)

      result must haveSize(6)

      val result2 = result collect {
        case (ids, SString(d)) if ids.length == 1 => d
      }

      result2 must contain("quirky7", "solstice + 77", "Monkey: [Brains]7", """("alpha", "beta", "gamma")7""", "  Whitespace       is   awesome  !!!1!!   7", "7")
    }
    "determine endsWith" in {
      val input = op2Input(endsWith, CString("y"), homStrings)

      val result = testEval(input)

      result must haveSize(6)

      val result2 = result collect {
        case (ids, SBoolean(d)) if ids.length == 1 => d
      }

      result2 must contain(true, false)
    }
    "determine codePointBefore with valid integer" in {
      val input = op2Input(codePointBefore, CLong(7), homStrings)

      val result = testEval(input)

      result must haveSize(4)

      val result2 = result collect {
        case (ids, SDecimal(d)) if ids.length == 1 => d
      }

      result2 must contain(99, 58, 97, 101)
    }
    "determine codePointBefore with invalid integer" in {
      val input = op2Input(codePointBefore, CNum(7.5), homStrings)

      val result = testEval(input)

      result must haveSize(0)

      val result2 = result collect {
        case (ids, SDecimal(d)) if ids.length == 1 => d
      }

      result2 must haveSize(0)
    }
    "determine takeLeft with valid integer" in {
      val input = op2Input(takeLeft, CLong(8), homStrings)

      val result = testEval(input)

      result must haveSize(6)
      val result2 = result collect {
        case (ids, SString(d)) if ids.length == 1 => d
      }

      result2 must contain("", "quirky", "solstice", "Monkey: ", "(\"alpha\"", "  Whites")
    }
    "determine takeRight with valid integer" in {
      val input = op2Input(takeRight, CLong(8), homStrings)

      val result = testEval(input)

      result must haveSize(6)
      val result2 = result collect {
        case (ids, SString(d)) if ids.length == 1 => d
      }

      result2 must contain("", "quirky", "tice + 7", "[Brains]", "\"gamma\")", "!!1!!   ")
    }
    "determine dropLeft with valid integer" in {
      val input = op2Input(dropLeft, CLong(8), homStrings)

      val result = testEval(input)

      result must haveSize(6)
      val result2 = result collect {
        case (ids, SString(d)) if ids.length == 1 => d
      }

      result2 must contain("", " + 7", "[Brains]", ", \"beta\", \"gamma\")", "pace       is   awesome  !!!1!!   ")
    }
    "determine dropRight with valid integer" in {
      val input = op2Input(dropRight, CLong(8), homStrings)
      val result = testEval(input)

      result must haveSize(6)
      val result2 = result collect {
        case (ids, SString(d)) if ids.length == 1 => d
      }

      result2 must contain("", "sols", "Monkey: ", "(\"alpha\", \"beta\", ", "  Whitespace       is   awesome  !")
    }
    "determine takeLeft with invalid integer" in {
      val input = op2Input(takeLeft, CNum(7.5), homStrings)
      testEval(input) must haveSize(0)
    }
    "determine takeRight with invalid integer" in {
      val input = op2Input(takeRight, CNum(7.5), homStrings)
      testEval(input) must haveSize(0)
    }
    "determine dropLeft with invalid integer" in {
      val input = op2Input(dropLeft, CNum(7.5), homStrings)
      testEval(input) must haveSize(0)
    }
    "determine dropRight with invalid integer" in {
      val input = op2Input(dropRight, CNum(7.5), homStrings)
      testEval(input) must haveSize(0)
    }
    "determine matches" in {
      val input = op2Input(matches, CString("quirky"), homStrings) //todo put regex here!

      val result = testEval(input)

      result must haveSize(6)

      val result2 = result collect {
        case (ids, SBoolean(d)) if ids.length == 1 => d
      }

      result2 must contain(true, false)
    }
    "determine matches with capture" in {
      val input = op2Input(regexMatch, CString(""".*(e)[^a]*(a)?[^a]*.*"""), homStrings)

      val result = testEval(input)
      result must haveSize(4)

      val result2 = result collect {
        case (ids, SArray(vec)) if ids.length == 1 => vec
      }

      result2 must contain(Vector(SString("e"), SString("a")), Vector(SString("e"), SString("")))
    }
    "determine compare" in {
      val input = op2Input(compare, CString("quirky"), homStrings) //todo put regex here!

      val result = testEval(input)

      result must haveSize(6)

      val result2 = result collect {
        case (ids, SDecimal(d)) if ids.length == 1 => d
      }

      result2 must contain(0, 2, -36, -73, -81, -6)
    }
    "determine compareIgnoreCase" in {
      val input = Join(BuiltInFunction2Op(compareIgnoreCase), Cross(None),
        dag.AbsoluteLoad(Const(CString("/hom/strings"))),
        Const(CString("QUIRKY")))

      val result = testEval(input)

      result must haveSize(6)

      val result2 = result collect {
        case (ids, SDecimal(d)) if ids.length == 1 => d
      }

      result2 must contain(0, 2, -4, -73, -81, -6)
    }
    "determine equals" in {
      val input = Join(BuiltInFunction2Op(library.equals), Cross(None),
        dag.AbsoluteLoad(Const(CString("/hom/strings"))),
        Const(CString("quirky")))

      val result = testEval(input)

      result must haveSize(6)

      val result2 = result collect {
        case (ids, SBoolean(d)) if ids.length == 1 => d
      }

      result2 must contain(true, false)
    }
    "determine indexOf" in {
      val input = Join(BuiltInFunction2Op(indexOf), Cross(None),
        dag.AbsoluteLoad(Const(CString("/hom/strings"))),
        Const(CString("e")))

      val result = testEval(input)

      result must haveSize(6)

      val result2 = result collect {
        case (ids, SDecimal(d)) if ids.length == 1 => d
      }

      result2 must contain(-1, 7, 4, 12, 6)
    }
    "determine equalsIgnoreCase" in {
      val input = Join(BuiltInFunction2Op(equalsIgnoreCase), Cross(None),
        dag.AbsoluteLoad(Const(CString("/hom/strings"))),
        Const(CString("QUIRKY")))

      val result = testEval(input)

      result must haveSize(6)

      val result2 = result collect {
        case (ids, SBoolean(d)) if ids.length == 1 => d
      }

      result2 must contain(true, false)
    }
  }

  "for heterogeneous sets, the appropriate string function" should {
    "determine length" in {
      val input = dag.Operate(BuiltInFunction1Op(library.length),
        dag.AbsoluteLoad(Const(CString("/het/strings"))))

      val result = testEval(input)

      result must haveSize(6)

      val result2 = result collect {
        case (ids, SDecimal(d)) if ids.length == 1 => d
      }

      result2 must contain(6, 12, 16, 26, 42, 0)
    }
    "determine trim" in {
      val input = dag.Operate(BuiltInFunction1Op(trim),
        dag.AbsoluteLoad(Const(CString("/het/strings"))))

      val result = testEval(input)

      result must haveSize(6)

      val result2 = result collect {
        case (ids, SString(d)) if ids.length == 1 => d
      }

      result2 must contain("quirky", "solstice + 7", "Monkey: [Brains]", """("alpha", "beta", "gamma")""", "Whitespace       is   awesome  !!!1!!", "")
    }
    "determine toUpperCase" in {
      val input = dag.Operate(BuiltInFunction1Op(toUpperCase),
        dag.AbsoluteLoad(Const(CString("/het/strings"))))

      val result = testEval(input)

      result must haveSize(6)

      val result2 = result collect {
        case (ids, SString(d)) if ids.length == 1 => d
      }

      result2 must contain("QUIRKY", "SOLSTICE + 7", "MONKEY: [BRAINS]", """("ALPHA", "BETA", "GAMMA")""", "  WHITESPACE       IS   AWESOME  !!!1!!   ", "")
    }
    "determine toLowerCase" in {
      val input = dag.Operate(BuiltInFunction1Op(toLowerCase),
        dag.AbsoluteLoad(Const(CString("/het/strings"))))

      val result = testEval(input)

      result must haveSize(6)

      val result2 = result collect {
        case (ids, SString(d)) if ids.length == 1 => d
      }

      result2 must contain("quirky", "solstice + 7", "monkey: [brains]", """("alpha", "beta", "gamma")""", "  whitespace       is   awesome  !!!1!!   ", "")
    }
    "determine isEmpty" in {
      val input = dag.Operate(BuiltInFunction1Op(isEmpty),
        dag.AbsoluteLoad(Const(CString("/het/strings"))))

      val result = testEval(input)

      result must haveSize(6)

      val result2 = result collect {
        case (ids, SBoolean(d)) if ids.length == 1 => d
      }

      result2 must contain(true, false)
    }
    "determine intern" in {
      val input = dag.Operate(BuiltInFunction1Op(intern),
        dag.AbsoluteLoad(Const(CString("/het/strings"))))

      val result = testEval(input)

      result must haveSize(6)

      val result2 = result collect {
        case (ids, SString(d)) if ids.length == 1 => d
      }

      result2 must contain("quirky", "solstice + 7", "Monkey: [Brains]", """("alpha", "beta", "gamma")""", "  Whitespace       is   awesome  !!!1!!   ", "")
    }

    "determine codePointAt with valid integer" in {
      val input = Join(BuiltInFunction2Op(codePointAt), Cross(None),
        dag.AbsoluteLoad(Const(CString("/het/strings"))),
        Const(CLong(7)))

      val result = testEval(input)

      result must haveSize(4)

      val result2 = result collect {
        case (ids, SDecimal(d)) if ids.length == 1 => d
      }

      result2 must contain(101, 32, 34, 115)
    }
    "determine codePointAt with invalid integer" in {
      val input = Join(BuiltInFunction2Op(codePointAt), Cross(None),
        dag.AbsoluteLoad(Const(CString("/het/strings"))),
        Const(CNum(7.5)))

      val result = testEval(input)

      result must haveSize(0)

      val result2 = result collect {
        case (ids, SDecimal(d)) if ids.length == 1 => d
      }

      result2 must haveSize(0)
    }
    "determine startsWith" in {
      val input = Join(BuiltInFunction2Op(startsWith), Cross(None),
        dag.AbsoluteLoad(Const(CString("/het/strings"))),
        Const(CString("s")))

      val result = testEval(input)

      result must haveSize(6)

      val result2 = result collect {
        case (ids, SBoolean(d)) if ids.length == 1 => d
      }

      result2 must contain(true, false)
    }
    "determine lastIndexOf" in {
      val input = Join(BuiltInFunction2Op(lastIndexOf), Cross(None),
        dag.AbsoluteLoad(Const(CString("/het/strings"))),
        Const(CString("s")))

      val result = testEval(input)

      result must haveSize(6)

      val result2 = result collect {
        case (ids, SDecimal(d)) if ids.length == 1 => d
      }

      result2 must contain(-1, 3, 14, 27)
    }
    "determine concat" in {
      val input = Join(BuiltInFunction2Op(concat), Cross(None),
        dag.AbsoluteLoad(Const(CString("/het/strings"))),
        Const(CString("7")))

      val result = testEval(input)

      result must haveSize(6)

      val result2 = result collect {
        case (ids, SString(d)) if ids.length == 1 => d
      }

      result2 must contain("quirky7", "solstice + 77", "Monkey: [Brains]7", """("alpha", "beta", "gamma")7""", "  Whitespace       is   awesome  !!!1!!   7", "7")
    }
    "determine endsWith" in {
      val input = Join(BuiltInFunction2Op(endsWith), Cross(None),
        dag.AbsoluteLoad(Const(CString("/het/strings"))),
        Const(CString("y")))

      val result = testEval(input)

      result must haveSize(6)

      val result2 = result collect {
        case (ids, SBoolean(d)) if ids.length == 1 => d
      }

      result2 must contain(true, false)
    }
    "determine codePointBefore with valid integer" in {
      val input = Join(BuiltInFunction2Op(codePointBefore), Cross(None),
        dag.AbsoluteLoad(Const(CString("/het/strings"))),
        Const(CLong(7)))

      val result = testEval(input)

      result must haveSize(4)

      val result2 = result collect {
        case (ids, SDecimal(d)) if ids.length == 1 => d
      }

      result2 must contain(99, 58, 97, 101)
    }
    "determine codePointBefore with invalid integer" in {
      val input = Join(BuiltInFunction2Op(codePointBefore), Cross(None),
        dag.AbsoluteLoad(Const(CString("/het/strings"))),
        Const(CNum(7.5)))

      val result = testEval(input)

      result must haveSize(0)

      val result2 = result collect {
        case (ids, SDecimal(d)) if ids.length == 1 => d
      }

      result2 must haveSize(0)
    }
    "determine takeLeft with valid integer" in {
      val input = Join(BuiltInFunction2Op(takeLeft), Cross(None),
        dag.AbsoluteLoad(Const(CString("/het/strings"))),
        Const(CLong(8)))

      val result = testEval(input)

      result must haveSize(6)
      val result2 = result collect {
        case (ids, SString(d)) if ids.length == 1 => d
      }

      result2 must contain("", "quirky", "solstice", "Monkey: ", "(\"alpha\"", "  Whites")
    }
    "determine takeRight with valid integer" in {
      val input = Join(BuiltInFunction2Op(takeRight), Cross(None),
        dag.AbsoluteLoad(Const(CString("/het/strings"))),
        Const(CLong(8)))

      val result = testEval(input)

      result must haveSize(6)
      val result2 = result collect {
        case (ids, SString(d)) if ids.length == 1 => d
      }

      result2 must contain("", "quirky", "tice + 7", "[Brains]", "\"gamma\")", "!!1!!   ")
    }
    "determine dropLeft with valid integer" in {
      val input = Join(BuiltInFunction2Op(dropLeft), Cross(None),
        dag.AbsoluteLoad(Const(CString("/het/strings"))),
        Const(CLong(8)))

      val result = testEval(input)

      result must haveSize(6)
      val result2 = result collect {
        case (ids, SString(d)) if ids.length == 1 => d
      }

      result2 must contain("", " + 7", "[Brains]", ", \"beta\", \"gamma\")", "pace       is   awesome  !!!1!!   ")
    }
    "determine dropRight with valid integer" in {
      val input = Join(BuiltInFunction2Op(dropRight), Cross(None),
        dag.AbsoluteLoad(Const(CString("/het/strings"))),
        Const(CLong(8)))

      val result = testEval(input)

      result must haveSize(6)
      val result2 = result collect {
        case (ids, SString(d)) if ids.length == 1 => d
      }

      result2 must contain("", "sols", "Monkey: ", "(\"alpha\", \"beta\", ", "  Whitespace       is   awesome  !")
    }
    "determine takeLeft with invalid integer" in {
      val input = op2Input(takeLeft, CNum(7.5), hetStrings)
      testEval(input) must haveSize(0)
    }
    "determine takeRight with invalid integer" in {
      val input = op2Input(takeRight, CNum(7.5), hetStrings)
      testEval(input) must haveSize(0)
    }
    "determine dropLeft with invalid integer" in {
      val input = op2Input(dropLeft, CNum(7.5), hetStrings)
      testEval(input) must haveSize(0)
    }
    "determine dropRight with invalid integer" in {
      val input = op2Input(dropRight, CNum(7.5), hetStrings)
      testEval(input) must haveSize(0)
    }
    "determine matches" in {
      val input = op2Input(matches, CString("quirky"), hetStrings) //todo put regex here!
      val result = testEval(input)

      result must haveSize(6)

      val result2 = result collect {
        case (ids, SBoolean(d)) if ids.length == 1 => d
      }

      result2 must contain(true, false)
    }
    "determine compare" in {
      val input = op2Input(compare, CString("quirky"), hetStrings)
      val result = testEval(input)

      result must haveSize(6)

      val result2 = result collect {
        case (ids, SDecimal(d)) if ids.length == 1 => d
      }

      result2 must contain(0, 2, -36, -73, -81, -6)
    }
    "determine compareIgnoreCase" in {
      val input = op2Input(compareIgnoreCase, CString("QUIRKY"), hetStrings)
      val result = testEval(input)

      result must haveSize(6)

      val result2 = result collect {
        case (ids, SDecimal(d)) if ids.length == 1 => d
      }

      result2 must contain(0, 2, -4, -73, -81, -6)
    }
    "determine equals" in {
      val input = op2Input(library.equals, CString("quirky"), hetStrings)
      val result = testEval(input)

      result must haveSize(6)

      val result2 = result collect {
        case (ids, SBoolean(d)) if ids.length == 1 => d
      }

      result2 must contain(true, false)
    }
    "determine indexOf" in {
      val input = Join(BuiltInFunction2Op(indexOf), Cross(None),
        dag.AbsoluteLoad(Const(CString("/het/strings"))),
        Const(CString("e")))

      val result = testEval(input)

      result must haveSize(6)

      val result2 = result collect {
        case (ids, SDecimal(d)) if ids.length == 1 => d
      }

      result2 must contain(-1, 7, 4, 12, 6)
    }
    "determine equalsIgnoreCase" in {
      val input = Join(BuiltInFunction2Op(equalsIgnoreCase), Cross(None),
        dag.AbsoluteLoad(Const(CString("/het/strings"))),
        Const(CString("QUIRKY")))

      val result = testEval(input)

      result must haveSize(6)

      val result2 = result collect {
        case (ids, SBoolean(d)) if ids.length == 1 => d
      }

      result2 must contain(true, false)
    }
  }

  "parseNum" should {
    "handle valid and invalid inputs" in {
      val input = dag.Operate(BuiltInFunction1Op(parseNum),
        dag.AbsoluteLoad(Const(CString("/het/stringNums"))))

      val result = testEval(input)

      result must haveSize(8)

      val ns = result.toList.collect {
        case (_, SDecimal(n)) => n
      }

      ns.toSet must_== Set[BigDecimal](
        BigDecimal("42"),
        BigDecimal("42.0"),
        BigDecimal("42.123"),
        BigDecimal("-666"),
        BigDecimal("2e3"),
        BigDecimal("0e9"),
        BigDecimal("2.23532235235235353252352343636953295923"),
        BigDecimal("1.2e3")
      )
    }
  }

  "toString" should {
    "convert values to strings" in {
      val input = dag.Operate(BuiltInFunction1Op(numToString),
        dag.AbsoluteLoad(Const(CString("/het/random"))))

      val result = testEval(input)

      result must haveSize(6)

      val ss = result.toList.collect {
        case (_, SString(s)) => s
      }

      ss must contain(
        "4",
        "3",
        "4",
        "4",
        "3",
        "4"
      )
    }

    "trim the trailing '.0' in round double conversion" in {
      val input = dag.Operate(BuiltInFunction1Op(numToString),
        dag.Operate(BuiltInFunction1Op(round),
          Const(CDouble(3.14))))

      val resultE = testEval(input)
      resultE must haveSize(1)

      val result = resultE.collect {
        case (_, SString(s)) => s
      }

      result must contain("3")
    }
  }

  "split" should {

    val o = scala.math.Ordering.by[(SValue, _), SValue](_._1)

    def mogrify(result: Set[(Vector[SValue], SValue)]): List[Vector[String]] =
      result.toList.collect {
        case (Vector(n), SArray(elems)) => (n, elems)
      }.sorted(o).map(_._2 collect { case SString(s) => s })

    def mktree(f: Op2, path: String, sep: String) =
      Join(BuiltInFunction2Op(f), Cross(None),
        dag.AbsoluteLoad(Const(CString(path))),
        Const(CString(sep)))

    def tester(f: Op2, path: String, sep: String) =
      mogrify(testEval(mktree(f, path, sep)))

    val commaSplitString2 = List(
      Vector("this", "is", "delimited"),
      Vector("this is a string"),
      Vector(""),
      Vector("also", "delmited"),
      Vector("", "starts", "with", "comma"),
      Vector("ends", "with", "comma", ""),
      Vector("lots", "", "", "", "of", "", "", "", "commas"),
      Vector("", "", "", "" , "", "", "", ""),
      Vector("", ""),
      Vector("", "", "crazy", "", ""),
      Vector("something", "basically", "reasonable")
    )

    "quote a regular expression in a split" in {
      val input = Join(BuiltInFunction2Op(split), Cross(None),
        Const(CString("foo{bar")),
        Const(CString("{")))

      testEval(input) collect {
        case (_, SArray(vec)) => vec collect { case SString(str) => str }
      } mustEqual Set(Vector("foo", "bar"))
    }

    "split heterogenous data on ," in {
      tester(split, "/het/strings2", ",") must_== commaSplitString2
    }

    "splitRegex heterogenous data on ," in {
      tester(splitRegex, "/het/strings2", ",") must_== commaSplitString2
    }

    "splitRegex heterogenous data on ,,+" in {
      tester(splitRegex, "/het/strings2", ",,+") must_== List(
        Vector("this,is,delimited"),
        Vector("this is a string"),
        Vector(""),
        Vector("also,delmited"),
        Vector(",starts,with,comma"),
        Vector("ends,with,comma,"),
        Vector("lots", "of", "commas"),
        Vector("", ""),
        Vector(","),
        Vector("", "crazy", ""),
        Vector("something,basically,reasonable")
      )
    }

    "splitRegex heterogenous data on invalid regex" in {
      tester(splitRegex, "/het/strings2", "(99") must_== List()
    }
  }
}

object StringLibSpecs extends StringLibSpecs[Need]

redpajama_set_name: RedPajamaGithub


Zeke Grader of the Pacific Coast Federation of Fisherman's Associations submitted himself to a virtual lynching on the Sean Hannity show last week, as the host broadcast live in front of a mob of Central Valley farmers.
Grader gave as good as he got, but guess what? Everyone lost.


text:
State spending at Soviet levels in some parts of the UK
The Times today publishes a regional breakdown of public spending as a share of GDP, produced by the Centre for Economics and Business Research. It makes fascinating, if worrying, reading.
In the UK as a whole, public spending has climbed to 44.1 per cent of GDP, 15th highest in the OECD and the same level as Germany. But in some regions, the share is well over 50 per cent. In Northern Ireland, a Soviet level of 70.5 per cent of GDP goes on state expenditure, while public spending as a share of regional income is higher in Wales, the North East, Scotland and the North West than in France, the OECD country with the highest share of public spending overall.
By contrast, public spending in the economically successful London and the South East is 31.4 per cent and 33.5 per cent respectively - below the level in Ireland, Australia and the US.
As the Times comments: "It is no coincidence that economic success in London and southeast England is partnered by smaller state incursions." Exactly.

redpajama_set_name: RedPajamaCommonCrawl


text:
Q: Использование parseInt Имеется пример кода на js:
<script>
var a = parseInt(prompt(A))
if(a == 0)
    {
        alert("A равно 0");
    }
    else if(a > 0)
    {
        alert("A положительное");
    }
    else if(a < 0)
    {
        alert("A отрицательное");
    }
    else
    {
        alert("похоже Вы ввели число");
    }
</script>

хочу сделать тоже самое на java:
public class Pr1 {
public static void main(String[] args) {
    System.out.println("введите число");
    Scanner scr = new Scanner(System.in);
    int n = scr.nextInt();

    if(n == 0)
    {
        System.out.println("N равно 0");
    }
    else if(n > 0)
    {
        System.out.println("N положительное");
    }
    else if(n < 0)
    {
        System.out.println("N отрицательное");
    }
    else
    {
        System.out.println("Вы ввели буквы");
    }
}
}

Вопрос: как в простом варианте (без использования while, for, do-while, т.к. этот материал еще не затрагивался - уместить в 1, 2 или 3 строчки код) используя parseInt, чтобы при вводе символов не выходила ошибка и на выходе было "Вы ввели буквы"?

A: Упростить можно только так. По - другому никак!
public class Main {
    public static void main(String[] args) {
        try {
            System.out.println("введите число");
            Scanner scr = new Scanner(System.in);
            int n = scr.nextInt();
            System.out.println(n == 0 ? "N равно 0" : n > 0
                    ? "N положительное" : "N отрицательное");
        } catch (InputMismatchException x) {
            System.out.println("Вы ввели буквы");
        }
    }
}

redpajama_set_name: RedPajamaStackExchange


text:
Q: Calling a function in parent component from a child component - React+flux+alt I am using flux+alt+es6 structure in my react application.I want to update parent state with my child component details.
Parent function:
handleChange(name, e) {
    const change = {};
    change[name] = e.target.value;
    this.setState(change);
    console.log('---state:--', this.state);
  }

Child Component:
import React from 'react';
import { Input, Button, Glyphicon } from 'react-bootstrap';

export default class TextBoxesSet extends React.Component {
  constructor(props) {
    super(props);
  }
  _onRemoveName = (id) => {
    this.props.name.slice(id, 1);
  }
  static getPropsFromStores() {
    return {name: 'en', description: '', AttributeSectionName: []};
  }

  render() {
    return (

          <Input type="select" placeholder="select" wrapperClassName="col-xs-4"
          value={this.props.name} onChange={this.handleChange.bind(this, 'name')} >
            <option value="one">One</option>
            <option value="two">Two</ption>
            <option value="three">Three</option>
          </Input>

          <Button bsSize="small"><Glyphicon glyph="remove" onClick={this._onRemoveName} /></Button>

    );
  }
  handleChange(name, e) {
    ParentComponent.handleChange(name, e);
  }
}
TextBoxesSet.propTypes = {
  name: React.PropTypes.object,
  description: React.PropTypes.object,
  AttributeSectionName: React.PropTypes.arrayOf(React.PropTypes.object)
};

How can I access function in parent component from a child component?

A: You pass it as a prop, f.ex:
<TextBoxesSet handleChange={this.handleChange} />

And then:
this.props.handleChange(name, e);

You need to add it as a propType as well:
handleChange: React.PropTypes.func

You might need to bind the correct context as well in the parent constructor if you need access to this in the function:
this.handleChange = this.handleChange.bind(this)


text:
Australian National Audit Office (ANAO)
Browse our range of publications including performance and financial statement audit reports, assurance review reports, information reports and annual reports.
Major projects report
ANAO 2019–20 Corporate Plan
Audit insights
Better practice guides
Opinions newsletter
Audit Focus newsletter
The ANAO work program outlines potential and in-progress work across financial statement and performance audit.
View the work program
View by portfolio
In-progress
Financial statement audit reports
Assurance reviews
Requests for audit
Auditor-General's responses to requests for audit
Our staff add value to public sector effectiveness and the independent assurance of public sector administration and accountability, applying our professional and technical leadership to have a real impact on real issues.
Assurance Audit Services Group
Performance Audit Services Group
Systems Assurance and Data Analytics Group
Assurance Projects Branch
Professional Services and Relationships Group
Working at the ANAO
The ANAO Graduate Program
Learning, development & training
Living in Canberra
APS employee census
Vacancies and applications
Contact ANAO careers
The Australian National Audit Office (ANAO) is a specialist public sector practice providing a range of audit and assurance services to the Parliament and Commonwealth entities.
The Auditor-General
Australian National Audit Office
The audit process
Publications, seminars, events & briefings
ANAO Corporate Plan 2019-20
Parliamentary briefings
External audits and reviews, and procurement
External audits and reviews
Annual procurement plan
Statement of legal service expenditure
Senate Order on Entity Contracts
Gifts and benefits register
Work ›
Performance audit ›
Conduct of the External Compliance Assurance Process pilot
Performance audit report
Auditor-General Report No. 2 of 2016–17
Please direct enquiries relating to reports through our contact page.
The audit objective was to assess the effectiveness of the Australian Taxation Office's External Compliance Assurance Process pilot conducted with large business taxpayers.
1. The Australian Taxation Office is responsible for the management of income tax issues for approximately 1400 large public groups and superannuation funds operating in Australia. In 2014–15, the two types of entity contributed $47.6 billion (or 65.5 per cent) of the total income tax receipts collected from companies and superannuation funds.1 In 2014–15, the Australian Taxation Office conducted a pilot to test the effectiveness and viability of large business taxpayers using either a registered company auditor or Australian Taxation Office staff to check eight different types of factual matters identified by the Australian Taxation Office as a potential error or omission in the taxpayer's annual tax return.2 The External Compliance Assurance Process pilot ran for approximately six months and involved 56 companies, of which 29 companies completed the full process. The cost to the Australian Taxation Office for the pilot and earlier concept design was approximately $1.05 million.
2. An Australian Taxation Office evaluation concluded that the pilot was successful, however, the Australian Taxation Office only endorsed the progressive introduction of the option for review by its own staff. In the May 2016 Federal Budget, savings for the Government of $5.7 million over four years from 2016–17 were to be achieved by implementing the Australian Taxation Office's external compliance assurance processes.
Audit objective and criteria
3. The objective of the audit was to assess the effectiveness of the Australian Taxation Office's External Compliance Assurance Process pilot conducted with large business taxpayers. To form a conclusion against this objective, the Australian National Audit Office adopted the following high-level audit criteria:
the Australian Taxation Office effectively assessed the future viability of the External Compliance Assurance Process for large business taxpayers; and
the Australian Taxation Office effectively conducted the External Compliance Assurance Process pilot.
4. The Australian Taxation Office's pilot of an external compliance assurance process for large business taxpayers was conducted effectively and demonstrated the potential for better client experiences, cost reductions and increased efficiency, by satisfactorily verifying factual matters in company tax returns. The pilot provided the Australian Taxation Office with a sound basis for conducting external compliance assurance processes for large business taxpayers in the future.
5. A number of key lessons have been identified for future Australian Taxation Office pilots and more widely for pilots in all public sector entities. The two categories of learnings address: for the Australian Taxation Office, the design and management of pilots of compliance processes; and, for all public sector entities, the benefits of trialling new ideas through pilots, the value of co-design, and the importance of establishing a sound evidence base for evaluating and reporting the outcomes from pilots.
Supporting findings
Evaluating the pilot
6. The Australian Taxation Office's External Compliance Assurance Process pilot met its objective of testing the effectiveness and viability of select large business taxpayers using a registered company auditor to check factual matters identified by the Australian Taxation Office. The Australian Taxation Office's deferral of a decision about having external company auditors undertake an agreed-upon procedures engagement on factual matters identified by the Australian Taxation Office in company tax returns took into account the extent of media criticism of the external process and ongoing parliamentary scrutiny of compliance by large corporate taxpayers at the time.
7. In 2016, the Australian Taxation Office has been developing a new compliance review for large business taxpayers that is based on the pilot and will be undertaken by Australian Taxation Office staff. The new review has the potential to deliver efficiencies for the Australian Taxation Office, including increasing the number of reviews conducted with large business taxpayers.
8. The pilot evaluation process and a Pilot Evaluation Report in 2015, jointly drafted by the Australian Taxation Office and a Steering Group for the pilot, was a reasonable basis for Australian Taxation Office decision-making about the future direction of the External Compliance Assurance Process for large business taxpayers. In the Pilot Evaluation Report, the potential for the External Compliance Assurance Process to deliver better client experiences, reduced costs and increased efficiency would have been more clearly demonstrated if a greater amount of the available quantitative evidence had been included to balance the qualitative commentary.
Designing and conducting the pilot
9. The pilot was well designed. The Australian Taxation Office considered international and Australian Government regulatory models and consulted broadly. The pilot approach—including the use of a standard issued by the Auditing and Assurance Standards Board on related services—was appropriate to treating the risk of incorrect reporting by large business taxpayers. Its detailed methodologies addressed design risks to an acceptable level, including ethical and independence concerns about the use of company auditors.
10. The concept design report was an appropriate basis for a decision to proceed to pilot. The report proposed two processes that could be tested and was supported by an Australian Taxation Office project management methodology.
11. The pilot was effectively conducted as a small project. It was managed according to the specified deliverables and budget; key senior executives were kept informed of the pilot's progress; and all participants were provided with adequate guidance. By the end of the pilot, the Australian Taxation Office had verified taxpayers' reporting of claims totalling approximately $1.1 billion in income, deductions and tax losses.
12. The Australian Taxation Office's integrity checks on five of 21 cases that used company auditors did not identify any non-compliance issues with the use of the Australian Taxation Office developed agreed-upon procedures. However, the integrity checks should have covered all of the company auditor cases and a proportionate checking process should have been extended to the reviews conducted by Australian Taxation Office staff to provide greater assurance. Further, while planning processes were sound, unexpected case selection issues contributed to a delay in completing the pilot.
13. The Australian Taxation Office implemented an adequate communication strategy for the pilot, including the design of the concept. The Australian Taxation Office did not evaluate the effectiveness of the communication strategy but did monitor, evaluate and act on media coverage during and after the pilot.
Key learnings
14. Based on the audit findings, the Australian National Audit Office has identified key learnings that could be applied to other Australian Taxation Office pilots of compliance processes, and key learnings that could be applied by other public sector entities. The two categories of learnings presented in Box 1 and Box 2 address the role of piloting in supporting program design and implementation and are not listed in order of priority.
Box 1: Key learnings for the Australian Taxation Office
A sound evidence base should be established to support any decision to expand external compliance assurance processes beyond large business taxpayers.
Planning for future pilots should include sufficient time to resolve case selection issues and establish a pool of taxpayer cases as early as possible when the pilot commences.
A proportionate focus on quality checking processes for Australian Taxation Office staff involved in a pilot would provide greater certainty for the staff involved and senior management about the introduction of a new review process.
Box 2: Key learnings that could be applied by other public sector entities
Comprehensive pilots, with detailed methodologies and project management arrangements, can be a useful form of trial where there is potentially strong community or sectoral opposition to an initiative.
If relevant to the individual circumstances, effective co-design of new methodologies and procedures with external stakeholders can contribute to the success of a pilot.
Pilots, including during the design phase, should be well documented and evidence based to support later conclusions and recommendations about the future viability of processes or programs.
Summary of entity response
15. The Australian Taxation Office's response to the report is provided below, while its full response is at Appendix 1.
The ATO welcomes this review and considers the report supportive of our overall approach to managing the income tax compliance of the large business market segment.
The review findings confirm the ATO's external compliance assurance process (ECAP) concept co-design, pilot and evaluation has provided the ATO with an innovative and sound basis for conducting ECAP work with large business clients in the future.
I was also pleased to note in particular, that we agree:
The ATO's assessment that the pilot concepts were viable was found to be an accurate reflection of the pilot's conduct and outcomes.
The pilot was conducted effectively and demonstrated the potential for better client experiences, cost reductions, and increased efficiency.
The use of the auditing standards framework was appropriate for treating factual income tax risks and the detailed methodologies addressed design risks to an acceptable level, including ethical and independence concerns about the use of company auditors.
The ATO appreciates the identified opportunities for improvement in the report and they will be considered as we move forward with our Reinvention Program.
The short performance Audit experience has been a positive experience for the ATO and we thank the Audit team for their work.
1.1 In Australia, large business taxpayers are an important element of the tax and superannuation systems. Together, large public groups and superannuation funds contribute over 60 per cent of all company and superannuation fund tax annually.3 The Australian Taxation Office (ATO) is responsible for the management of income tax issues for the approximately 1400 large public groups and superannuation funds that were operating in Australia in 2014–15.4
1.2 In 2012, following suggestions from accounting firms and the Inspector-General of Taxation5, the ATO began exploring a new verification and validation compliance process for large business taxpayers. In December 2013, the ATO consulted a broad range of stakeholders on the new process. The outcome of the ATO consultation process was an External Compliance Assurance Process (ECAP) pilot. The pilot participants could choose either a report by a registered company auditor or streamlined review by ATO staff to check factual matters identified by the ATO as a potential error in their annual income tax return (Figure 1.1).
Figure 1.1: External Compliance Assurance Process pilot
Source: ANAO analysis of ATO documents.
1.3 The activity undertaken by the company auditor was to apply a standard issued by the Auditing and Assurance Standards Board on related services to the work.6 Under an agreed-upon procedures engagement, the auditor prepares a factual report in accordance with the procedure, but does not offer assurance or provide an opinion or conclusion. The decision-maker, in this case the ATO, draws its own conclusions based on the factual report and any other available information, for example, information from taxpayer lodgements. The ATO and stakeholders consulted by the Australian National Audit Office (ANAO) identified advantages from using agreed-upon procedures engagements, including greater certainty for both taxpayers and the ATO about the tax issue being investigated and the information necessary to resolve it.
1.4 Figure 1.2 shows the timeline for the development of the design concept, implementation and evaluation of the ECAP pilot, and ATO consideration of the Pilot Evaluation Report. The pilot ran for approximately six months and involved 56 companies. The companies were rated as low or medium risk by the ATO and had an annual turnover of between $100 million and $5 billion.
Figure 1.2: Timeline for the External Compliance Assurance Process pilot
Source: ANAO analysis of ATO information.
Audit approach
1.5 The objective of the audit was to assess the effectiveness of the Australian Taxation Office's External Compliance Assurance Process pilot conducted with large business taxpayers. To form a conclusion against this objective, the ANAO adopted the following high-level audit criteria:
the ATO effectively assessed the future viability of the ECAP for large business taxpayers; and
the ATO effectively conducted the ECAP pilot.
1.6 Audit fieldwork was largely conducted in April 2016. During this time, the audit team: reviewed documentation and interviewed key ATO staff; analysed data for the pilot cases; and consulted with a broad range of stakeholder groups, including companies and their auditors, government entities and tax professional associations.
1.7 The audit was conducted in accordance with the ANAO Auditing Standards at a cost to the ANAO of approximately $180 000.
2. Evaluating the pilot
Areas examined
This chapter examines whether the External Compliance Assurance Process (ECAP) pilot met its objective and was evaluated effectively to support a decision about the future viability of the process.
The Australian Taxation Office's (ATO) evaluation of the ECAP pilot in 2015 concluded that the pilot had met its objective and provided a reasonable basis for ATO decision-making about the future viability of the ECAP. While the ATO decided not to proceed immediately with an ECAP for large business taxpayers, specific issues and their potential mitigations were identified should the process be implemented later. The pilot has supported the ATO to begin implementing a new review approach for its staff working with large business taxpayers.
Area for improvement
The Pilot Evaluation Report could have contained more quantitative reporting of the results from the pilot's assessment process in order to balance the qualitative commentary (paragraph 2.12).
Did the pilot achieve its objective and is the Australian Taxation Office implementing a new process?
The ATO's ECAP pilot met its objective of testing the effectiveness and viability of select large business taxpayers using a registered company auditor to check factual matters identified by the ATO. The ATO's deferral of a decision about having external company auditors undertake an agreed-upon procedures engagement on factual matters identified by the ATO in company tax returns took into account the extent of media criticism of the external process and ongoing parliamentary scrutiny of compliance by large corporate taxpayers at the time.
In 2016, the ATO has been developing a new compliance review for large business taxpayers that is based on the pilot and will be undertaken by ATO staff. The new review has the potential to deliver efficiencies for the ATO, including increasing the number of reviews conducted with large business taxpayers.
2.1 The ATO's objective in conducting the ECAP pilot was to test the effectiveness and viability of large business taxpayers using a registered company auditor to check factual matters. The factual matters to be clarified were identified by the ATO in the taxpayer's annual 2012–13 tax return.
2.2 In October 2015, the ATO publicly announced that the pilot had been successful in meeting its objective. The pilot's success was in the context of testing a new process with a small, select number of large business taxpayers (see Chapter 3 for details of the pilot methodology).
2.3 The pilot successfully tested two new elements of ATO activity:
the ability to write an agreed-upon procedure for company auditors to apply and produce a factual findings report to support ATO decision-making; and
in order to offer taxpayers a choice of reviewer—whether ATO staff could use a streamlined review approach, to obtain a comparable level of information to an agreed-upon procedures engagement, to support its decision-making about a taxpayer's income tax return.
2.4 The ATO evaluated the success of the pilot against its objective (paragraph 2.1) and the four key measures in Table 2.1, which encompassed the two elements of ATO activity.
Table 2.1: Four key measures for the pilot
ATO explanation of the measure's intention
Enhanced client experience
Is the taxpayer's experience in dealing with the ATO better?
Reduced compliance cost and red tape
Has the ATO streamlined the approach for both taxpayers and ATO staff?
Cost-effective assurance over a larger proportion
Does the process tested offer a competitive and effective approach overall for a potentially greater number of large business taxpayers?
More efficient use of ATO resources
Does the ECAP support improved case management by ATO staff?
Source: Australian National Audit Office (ANAO) analysis of ATO documents.
2.5 The ATO's assessment of the pilot being a success, against the objective and four key measures, was an accurate reflection of the pilot's conduct and outcomes. The ATO's evaluation process is discussed in paragraphs 2.9–2.17.
2.6 In October 2015, the ATO deferred making a decision about having external company auditors undertake an agreed-upon procedures engagement on factual matters identified by the ATO in company tax returns. The ATO's decision on timing for the introduction of an external review process for large business taxpayers reflected an awareness of media coverage and ongoing parliamentary processes. In 2014–15, the ATO was aware of and monitored negative coverage in the media of the ATO's design and piloting activities for the ECAP, which focused on perceptions of company auditors' independence (see Chapter 3). Postponing the decision also allowed the ATO to consider the implications of an ongoing Senate Economics References Committee inquiry report into corporate tax avoidance.7
2.7 The ATO announced that it would progressively introduce a new review process to the compliance strategies available for ATO staff working with large business taxpayers. Since February 2016, the ATO has been developing the new streamlined review process tested during the pilot, including training packages for staff. The pilot demonstrated the potential for the new review to reduce the time taken for a streamlined review and increase the number of reviews undertaken by the ATO.8
2.8 In the May 2016 Federal Budget, savings for the Government of $21.8 million over four years from 2016–17 were to be achieved by, among other strategies, implementing the ATO's external compliance assurance processes.9 The ATO advised that the expected saving from using external compliance assurance processes is $5.7 million over four years.
Did the pilot evaluation support effective Australian Taxation Office decision-making about the future of the external compliance assurance process for large business taxpayers?
The pilot evaluation process and a Pilot Evaluation Report in 2015, jointly drafted by the ATO and a Steering Group for the pilot, was a reasonable basis for ATO decision-making about the future direction of the ECAP for large business taxpayers.
In the Pilot Evaluation Report, the potential for the ECAP to deliver better client experiences, reduced costs and increased efficiency would have been more clearly demonstrated if a greater amount of the available quantitative evidence had been included to balance the qualitative commentary.
2.9 Central to the ATO's evaluation process for the ECAP pilot was the formation of a Steering Group that operated from August 2014 to April 2015 and comprised representatives from tax professional associations and the ATO. The Steering Group was established to oversee the pilot by providing: strategic and technical advice; and advising on the pilot evaluation and future direction.
2.10 The ATO drafted an evaluation framework for the pilot and included the four key measures in Table 2.1, which were developed in consultation with the Steering Group.
2.11 The Pilot Evaluation Report drafted by the ATO and the Steering Group was finalised in 2015. The findings in the Pilot Evaluation Report, against the key measures, were based on an assessment of information from: telephone surveys; unsolicited feedback; ATO data and reports; interviews and group workshops; and integrity checks of pilot cases. Table 2.2 summarises the final assessment of the pilot that was presented in the Pilot Evaluation Report.
Table 2.2: Pilot Evaluation Report: High-level summary of the final assessment of the External Compliance Assurance Process pilot
Key measure
Type of indicator
ATO assessment
A total of 12 indicators, comprised of four types of indicator (qualitative and quantitative):
inputs to the pilot;
pilot activities and support processes;
deliverables from the pilot; and
Results supported the key measure
Results offered qualified support for the key measurea
Cost-effective assurance over a higher proportion [of large business taxpayers]
Results offered qualified support for the key measureb
Note a: The ATO concluded that the ECAP: 'could reduce compliance costs and does reduce red tape'. The ATO did not have complete information and could not quantify the cost to the taxpayer of their choice of company auditor or the ATO.
Note b: The ATO concluded that the ECAP: 'has the potential to deliver a cost effective assurance'.
Source: External Compliance Assurance Process Pilot Evaluation Report, 2015, and ANAO analysis of ATO documents.
2.12 Overall, the ATO established a sound evaluation framework for the pilot's final assessment and evaluation and there was a reasonable evidence base for the findings. The Pilot Evaluation Report could have been improved by including baseline data or specified targets with the quantitative indicators, particularly to support reporting on the measurement of reduced compliance costs and providing cost-effective assurance over an increased number of large business taxpayers.
2.13 Four ECAP stakeholders that contacted the ANAO during the audit commented on the cost for companies of using their auditors to undertake review processes for the ATO. The stakeholders considered that the cost could, to some degree, be offset by a saving in company staff time that would otherwise have been needed to support a solely ATO review. A potential issue for future reviews that was identified by one respondent was the concern that transferring review or audit costs from the ATO to companies could become the norm.
Consideration of implementation risk
2.14 The Pilot Evaluation Report explicitly considered implementation risks, identifying five issues that were specific to the ECAP pilot and suggesting potential mitigation activities for each if the process was to be introduced. The issues were:
negative media coverage during the design process and pilot (see Figure 2.1);
challenges in adopting new work processes in the ATO;
the case management process available for the pilot was based on a 120 day period and cases were planned for that period of time, even though less time was actually required for ECAP cases;
lengthy periods without the ATO initiating contact with the taxpayer between key stages of the process; and
problems with identifying suitable taxpayer cases that met the pilot's selection criteria.
Figure 2.1: Examples of negative media coverage of the external compliance assurance process
Source: ATO document, 2014.
2.15 The mitigation treatments suggested were sufficiently detailed that they could be put into operation by the ATO and the changes in approach monitored for improvements. For example, in addressing negative media coverage (as outlined in Figure 2.1), the ATO's mitigation strategies included communicating the broader context for the process and the use of agreed-upon procedures engagements as a verification activity. The ATO's Pilot Evaluation Report did not identify any lessons learnt that could be applied to other ATO pilots.
Pilot approval
2.16 The Pilot Evaluation Report was completed after the evaluation process and formed the basis for ATO executive decision-making about the future direction of the ECAP. As expected, a draft report was developed iteratively between the pilot team and senior management with a focus on the clarity of the recommendations being made for the future of the external compliance assurance process. The senior managers involved in the drafting and clearance process for the report made minimal requests to the pilot team for extra discussion or clarification.
2.17 The ATO Executive accepted the evaluation report's findings, conclusions and recommendations, which were subsequently publicly reported. The approval process was straightforward with no record of there being any concern about the content of the report. The final Pilot Evaluation Report was a reasonable basis for ATO decision-making about the future direction of the ECAP for large business taxpayers.
3. Designing and conducting the pilot
This chapter examines whether the Australian Taxation Office (ATO) effectively designed and conducted the External Compliance Assurance Process (ECAP) pilot.
A comprehensive co-design process with external and internal stakeholders was well-managed by the ATO and effectively supported the development of the pilot concept. The pilot was effectively conducted as a small project, notwithstanding that unexpected case selection issues contributed to a delay in completing the pilot, and there was scope for greater assurance if the integrity and quality checks had been improved.
The Australian National Audit Office (ANAO) has identified areas for improvement to be considered in the conduct of similar pilots in the future, including that the ATO: Internal Audit unit reviews the conduct of large, high profile or high risk pilots (paragraph 3.12); allows sufficient time to test a reliable case selection process (paragraph 3.13); and conducts proportionate quality checks on all key review processes (paragraphs 3.19–3.21).
Was the pilot well designed and based on a sound approach to address the risk of incorrect reporting by large business taxpayers?
The pilot was well designed. The ATO considered international and Australian Government regulatory models and consulted broadly. The pilot approach—including the use of a standard issued by the Auditing and Assurance Standards Board on related services—was appropriate to treating the risk of incorrect reporting by large business taxpayers. Its detailed methodologies addressed design risks to an acceptable level, including ethical and independence concerns about the use of company auditors.
The concept design report was an appropriate basis for a decision to proceed to pilot. The report proposed two processes that could be tested and was supported by an ATO project management methodology.
3.1 In February 2014, the ATO formally approved resources (including a budget of $400 000) to design the concept for a new compliance process to verify factual matters for large business taxpayers. The project was managed according to ATO project requirements and had a timeline of around six months, from December 2013 to May 2014.
3.2 In developing and testing a design concept, the ATO considered taxation models in Singapore, the Netherlands and the United States of America, and the audit requirements for Australian self-managed superannuation funds. The ATO also consulted with a broad range of stakeholders (Table 3.1). The ATO reported that the co-design and consultation process was effective and provided a model approach for future ATO consultations. In discussions with the ANAO, stakeholders involved in the consultation process supported the ATO's view, and noted that the ATO was receptive to suggestions from stakeholders.
Table 3.1: Australian Taxation Office consultation with external stakeholders
Representatives from:
tax professional associations
accounting and law firms
Australian Government regulatory bodies
public sector unions
Working groups:
the role and fit of tax advice
auditor independence
materiality and assurance
15 in total
Individual stakeholder meetings
Information sessions in capital cities
Large business taxpayers
3.3 The pilot approach—including the use of a standard issued by the Auditing and Assurance Standards Board on related services for an agreed-upon procedures engagement—was appropriate to treating the risk of incorrect reporting by large business taxpayers. The concept design report concluded that agreed-upon procedures engagements addressed most risks associated with the proposed approach to an acceptable level.10 The auditor independence working group and representatives from Australian Government regulatory and other governing bodies (with responsibility for overseeing company auditors' compliance with professional, ethical and auditing standards) agreed that the use of an agreed-upon procedures engagement for the design concept addressed most ethical and independence concerns. An ATO survey of taxpayers also indicated broad support for the proposed approach, with efficiency and certainty most often cited as the key benefits.
3.4 The ATO subsequently identified eight factual matters where there was a risk of incorrect reporting by large business taxpayers and developed agreed-upon procedures for each in consultation with selected stakeholders. The eight factual matters the ATO developed agreed-upon procedures for were: Capital Gains Tax Net Capital Losses; Capital Gains Incorrect Reporting; Research and Development Recoupment; Tax Losses (two risks); Capital Allowances Project Asset Pools (two risks); and Software Income. Stakeholder feedback to the ANAO was that the agreed-upon procedures were well drafted.
3.5 Consistent with ATO project planning requirements, the ATO identified and assessed risks arising from the design concept for the ECAP, but did not prepare a consolidated risk assessment and treatment plan. The ATO also separately identified and assessed potential risks to the ATO's fraud control environment associated with the ECAP. While it would have been valuable to the ATO to formally review the risks and mitigation measures at the close of the pilot, the ATO advised that risks were reviewed incrementally by integrity checking a sample of company auditor cases (see paragraph 3.19) and undertaking the evaluation process that supported drafting of the Pilot Evaluation Report and recommendations.
3.6 The concept design report recommended that the ATO pilot a design concept that:
provided pilot participants with a choice of reviewer—their existing company auditor or the ATO11;
tested the ATO developed agreed-upon procedures, where pilot participants chose their existing company auditor as the reviewer; and
tested a streamlined ATO review process where pilot participants chose the ATO as the reviewer.
3.7 The concept design report also set out the scope of the pilot, resources, timeline and risks. The ATO approved the pilot, in June 2014, based on the concept design report recommendations. The concept design report was an appropriate basis for a decision to proceed to pilot. The report: confirmed the agreement between the ATO and key stakeholders that the proposed design concept was appropriate; proposed two processes that could be tested; and was supported by an ATO project management methodology.
Was the pilot effectively conducted?
The pilot was effectively conducted as a small project. It was managed according to the specified deliverables and budget; key senior executives were kept informed of the pilot's progress; and all participants were provided with adequate guidance. By the end of the pilot, the ATO had verified taxpayers' reporting of claims totalling approximately $1.1 billion in income, deductions and tax losses.
The ATO's integrity checks on five of 21 cases that used company auditors did not identify any non-compliance issues with the use of the ATO developed agreed-upon procedures. However, the integrity checks should have covered all of the company auditor cases and a proportionate checking process should have been extended to the reviews conducted by ATO staff to provide greater assurance. Further, while planning processes were sound, unexpected case selection issues contributed to a delay in completing the pilot.
Conduct of the pilot
3.8 The ATO scheduled the pilot from 1 July to 31 October 2014 with an evaluation report to be prepared by March 2015. There were a number of case selection parameters for pilot cases. The ATO selected large business taxpayers that:
were rated as medium or lower risk under the ATO's risk modelling processes;
had an annual turnover between $100 million and $5 billion; and
had reported against one of the eight factual matters in their 2012–13 tax return.
3.9 The ATO planned to select 32 cases for the pilot between May and June 2014—16 cases to test the agreed-upon procedures developed by the ATO for use by company auditors and 16 cases to test the ATO streamlined review process. Case work commenced in August 2014. The ATO:
provided adequate guidance and standards for completing the agreed-upon procedures engagement and internal review process12;
made a final decision on the factual findings reports provided by company auditors; and
performed integrity checks on a sample of cases completed by company auditors.
3.10 From 2013–14 to 2014–15, the ATO's total budget for the ECAP concept development ($400 000) and pilot ($830 000) was $1.23 million. The actual cost to the ATO for ECAP, of $1.05 million, was 85 per cent of the approved budget.
3.11 The ATO implemented sound governance arrangements, including oversight by a Steering Group, as discussed in Chapter 2. The ATO also regularly briefed senior executives on the progress of the pilot. The ATO met the monthly project management reporting requirements and also produced a monthly high-level report that met other ATO internal reporting requirements. The ATO provided the Steering Group with a status report at each meeting.
3.12 In order to strengthen the governance and assurance practices for major projects and programs, the Australian Government Department of Finance has responsibility for a Gateway Review Process.13 The process involves a series of short, intensive reviews being conducted at critical points for projects and programs. Similarly, when the ATO is conducting large, high profile or high risk pilots, the addition of an early health check on key elements of the project by the ATO's Internal Audit area would provide additional assurance about the pilot's progress. The review could include: monitoring progress against key milestones; comparing the planned to actual budget; and assessing variations to the planned methodology that could affect the timing or conduct of the final evaluation. A review during the pilot would also give a Steering Group the opportunity to implement any recommended changes to the pilot methodology in a timely way.
3.13 The pilot was conducted from July 2014 until January 2015 some three months longer than originally planned, and the timeline was formally varied. The pilot coincided with a peak workload period for accounting firms and the ATO received requests for extensions from company auditors. The ATO also encountered unexpected case selection issues early in the pilot that contributed to delays in pilot casework. Case selection issues included identifying suitable taxpayers that were not subject to another ATO audit or review process. Sixteen out of 56 cases did not complete the pilot process because of case selection issues, for example, the ATO's risk filters were ineffective for some tax risks and identified taxpayers that were not eligible to participate in the pilot because they did not have a suitable risk. When planning for a pilot, the ATO should allow sufficient time to resolve case selection issues and establish a pool of taxpayer cases as early as possible when the pilot commences.
3.14 Another 11 cases did not proceed to pilot, including five companies that had completed a nomination form and selected one of the two review processes. Of these 11 cases: nine were unsuitable because the large business taxpayer (or their representative) identified an incorrect reporting issue in their 2012–13 return for the factual risk and were unable to complete the agreed-upon procedures as a result; one did not proceed because the taxpayer was in the process of negotiating an advance pricing agreement with the ATO; and another was not pursued due to delays in the ATO making contact with the taxpayer.
3.15 The remaining 29 cases completed one of the two pilot processes (Figure 3.1). Twenty-one cases completed the company auditor process and eight the ATO streamlined review process. The ATO was unable to provide an exact population figure for the total number of taxpayers that met all of the selection criteria and would have been eligible for the pilot. On completion of the relevant process, the ATO closed all 29 cases with no further action required for pilot purposes.
Figure 3.1: Cases involved in the pilot process
Source: ANAO analysis of ATO information, as at September 2015.
3.16 The ANAO's analysis of the pilot cases differs from the ATO's.14 The ATO's evaluation reported on the cases underway as at 30 January 2015, after which no new nominations were accepted. The ANAO's analysis was of ATO documents for cases completed up to September 2015, which the ATO has agreed with given the difference in timing and available information.
3.17 Of the 40 pilot cases referred to in paragraphs 3.14–3.15, the ATO advised that there were four outcomes:
the ATO referred the taxpayer for further action (audit or review) (one case);
the taxpayer made a prompted voluntary disclosure (16 cases) 15;
the ATO issued an amended assessment (four cases); and
the ATO was able to verify the relevant factual issue (19 cases).
3.18 By the end of the pilot, the ATO had verified taxpayers' reporting of claims totalling approximately $1.1 billion in income, deductions and tax losses.
Integrity checks and quality checks
3.19 The ATO also conducted integrity checks on five of the 21 pilot cases that used company auditors. The checks had multiple purposes: to satisfy the ATO that professional and ethical requirements had been considered and company auditors had complied with the ATO procedures; and to substantiate factual findings reports. It was appropriate for the ATO to review and form a judgement on whether company auditor factual findings reports satisfied ATO procedures. The ATO procedural requirements for the pilot acknowledged that it does not have a role in regulating professional and ethical auditing standards.
3.20 The ATO did not identify any non-compliance issues with the use of the ATO developed agreed-upon procedures. No external auditor findings were overturned or referred for further ATO action (audit or review) as a result of an integrity check. However, given the small pilot sample size, potential reputational risk to the ATO and interest from both internal and external stakeholders, the ATO should have conducted integrity checks on all of the company auditor pilot cases. The additional checks would have increased the ATO's understanding of the work undertaken by company auditors and the operation of the pilot, while also addressing potential risks for the ATO.
3.21 The ATO had assessed that there was a greater risk of ATO procedures not being followed by external company auditors than by its own staff. Therefore, the eight pilot cases that involved the ATO streamlined review process underwent: routine checks at key decision points by team leaders; and on-site peer review processes. A reliance on standard system checks meant that the ATO pilot team did not have the same benefit from an independent or external check that was applied to the work undertaken by the company auditors. No ATO pilot cases were selected for review under the ATO's enterprise-wide quality assurance framework, ATO Quality. Given the ECAP pilot involved a new ATO team, procedures and training, a proportionate focus on independent quality checking processes would have provided greater certainty about the implementation of a new review process for the ATO staff involved and senior management.
Did the Australian Taxation Office implement and evaluate an adequate communication strategy for the pilot?
The ATO implemented an adequate communication strategy for the pilot, including the design of the concept. The ATO did not evaluate the effectiveness of the communication strategy but did monitor, evaluate and act on media coverage during and after the pilot.
3.22 In March 2014, the ATO developed an overarching communication strategy to inform and/or consult ATO staff and external stakeholders. The communication strategy also sought to reassure ATO staff that the pilot was not seeking to outsource work undertaken by ATO staff.
3.23 The communication strategy identified key: risks and mitigation strategies; internal and external target audiences; and messages. Importantly, a key risk identified by the strategy was negative media scrutiny around perceptions of auditor independence. The communication strategy also identified a range of delivery channels including ATO newsletters, targeted email and correspondence, media briefings and releases and the ATO website.
3.24 The ATO did not evaluate the overall effectiveness of the ECAP pilot communication strategy but did monitor, evaluate and act on media coverage throughout the pilot, including writing letters to the editor to correct misreporting in the media.
Appendix 1: Entity response
1 Australian Taxation Office, Annual report 2014–15, October 2015, Canberra, p. 49.
2 The eight factual matters identified were: Capital Gains Tax Net Capital Losses; Capital Gains Incorrect Reporting; Research and Development Recoupment; Tax Losses (two risks); Capital Allowances Project Asset Pools (two risks); and Software Income.
3 In 2014–15, the two types of entity contributed $47.6 billion (or 65.5 per cent) of the total income tax receipts collected from companies and superannuation funds. Australian Taxation Office, Annual report 2014–15, October 2015, Canberra, p. 49.
4 In 2015–16, the ATO estimated that there were approximately 9000 public groups, including large business taxpayers. Public groups include Australian companies listed on an Australian stock exchange, and Australian trusts, partnerships and superannuation funds.
5 Inspector-General of Taxation, Review into improving the self assessment system, 2013, pp. 94 and 97.
6 Standard on Related Services ASRS 4400, Agreed-Upon Procedures Engagements to Report Factual Findings, 1 July 2013, available from <http://www.auasb.gov.au/admin/file/content102/c3/Jul13_Standard_on_ Related_Services_ASRS_4400.pdf> [accessed 26 May 2016].
7 Details of the inquiry into tax avoidance and aggressive minimisation by corporations registered in Australia and multinational corporations operating in Australia are available from <http://www.aph.gov.au/ Parliamentary_Business/Committees/Senate/Economics/Corporate_Tax_Avoidance>, [accessed 2 May 2016].
8 The ATO calculated that the external auditors' activity took an average of 87 days to complete a case, based on the results from 12 pilot cases. The ATO's review activity took an average of 93 days to complete a case, based on the results from seven pilot cases. The ATO compared those averages to an existing streamlined review process with an average time taken to complete cases of 132 days. The ATO concluded that the ECAP case timelines were efficient.
9 Australian Government, Budget Measures: Budget Paper No. 2: 2016–17, Commonwealth of Australia, Canberra, 2016, p. 149.
10 ATO, External Compliance Assurance Process (ECAP) Concept Report, 5 June 2014, p. 3.
11 During the pilot, the ATO allowed pilot participants the alternative of using another registered company auditor.
12 During the pilot, the ATO published information for company auditors, including guidance on their role and applying the agreed-upon procedures, and questions and answers.
13 Department of Finance, Gateway Reviews, available from <https://www.finance.gov.au/assurance-reviews/review-process/> [accessed 15 June 2016].
14 The ATO website states that 56 taxpayers were involved in the pilot: 20 taxpayers that chose to engage a company auditor; nine cases that chose to be reviewed by the ATO; 12 cases that were resolved prior to the taxpayer electing either the company auditor or ATO process; and 15 cases that were withdrawn during the early stages of the pilot. The advice is available from <https://www.ato.gov.au/business/large-business/in-detail/compliance-and-governance/external-compliance-assurance-process/> [accessed 15 June 2016].
15 A prompted voluntary disclosure is where a taxpayer discloses an error after the ATO has notified the taxpayer of its intention to review the taxpayer's affairs. In these circumstances the ATO may significantly reduce some penalties.
Auditor-General Grant Hehir
Graduate Program facebook
Bottom Footer
Public Interest Disclosure Scheme