title: Primality Test Set 1 Introduction And School Method 1
signature: function primality_test_set_1_introduction_and_school_method_1(n)
source_py: def primality_test_set_1_introduction_and_school_method_1(n):
      if (n <= 1):
          return False
      if (n <= 3):
          return True
      if (((n % 2) == 0) or ((n % 3) == 0)):
          return False
      i = 5
      while ((i * i) <= n):
          if (((n % i) == 0) or ((n % (i + 2)) == 0)):
              return False
          i = (i + 6)
      return True
source_cpp: bool primality_test_set_1_introduction_and_school_method_1(int n) {
    if ( n <= 1 ) return false;
    if ( n <= 3 ) return true;
    if ( n % 2 == 0 || n % 3 == 0 ) return false;
    for ( int i = 5;
    i * i <= n;
    i = i + 6 ) if ( n % i == 0 || n % ( i + 2 ) == 0 ) return false;
    return true;
  }
question_info.test_code: 
  
  -- SOLUTION CODE
  -- ============================================
  PLACEHOLDER_CODE_BODY
  
  -- TESTING CODE 
  -- ============================================
  function isCorrect(actual, expected)
      if type(expected) ~= type(actual) then
          return false
      end
      
      if type(expected) == 'table' then
          for k,v_expected in pairs(expected) do
              
              if actual[k] == nil then
                  return false
              end
              local v_actual = actual[k]
              if not isCorrect(v_actual, v_expected) then
                  return false
              end
              actual[k]=nil
          end
      
          if next(actual) then 
              return false
          end
          return true
      else
          return actual == expected
      end
  end
  
  function validateSolution(actual, expected)
      return isCorrect(actual,expected)
  end
  
  function driver(n, expected)
      local exec_result;
      local status, error_msg = pcall(function () 
          exec_result=PLACEHOLDER_FN_NAME(n) 
      end)
      if status then
          if validateSolution(exec_result,expected) then
              return "PASSED"
          end
          return "FAILED"
      else
          return string.format("ERROR=%s",string.gsub(error_msg,".*:[%d]+: ",""))
      end
  end
      
  function main()
      result = driver(15, false)
      print(string.format("TEST-0...%s",result))
  
      result = driver(90, false)
      print(string.format("TEST-1...%s",result))
  
      result = driver(38, false)
      print(string.format("TEST-2...%s",result))
  
      result = driver(65, false)
      print(string.format("TEST-3...%s",result))
  
      result = driver(91, false)
      print(string.format("TEST-4...%s",result))
  
      result = driver(16, false)
      print(string.format("TEST-5...%s",result))
  
      result = driver(48, false)
      print(string.format("TEST-6...%s",result))
  
      result = driver(74, false)
      print(string.format("TEST-7...%s",result))
  
      result = driver(14, false)
      print(string.format("TEST-8...%s",result))
  
      result = driver(47, true)
      print(string.format("TEST-9...%s",result))
  
  end
  
  main()
question_info.entry_cls_name: Solution
question_info.test_list: [{"idx": 0, "outputs": false, "inputs": {"n": 15}}, {"idx": 1, "outputs": false, "inputs": {"n": 90}}, {"idx": 2, "outputs": false, "inputs": {"n": 38}}, {"idx": 3, "outputs": false, "inputs": {"n": 65}}, {"idx": 4, "outputs": false, "inputs": {"n": 91}}, {"idx": 5, "outputs": false, "inputs": {"n": 16}}, {"idx": 6, "outputs": false, "inputs": {"n": 48}}, {"idx": 7, "outputs": false, "inputs": {"n": 74}}, {"idx": 8, "outputs": false, "inputs": {"n": 14}}, {"idx": 9, "outputs": true, "inputs": {"n": 47}}]
question_info.extension: lua
question_info.entry_fn_name: primality_test_set_1_introduction_and_school_method_1
question_info.test_case_ids: 0 1 2 3 4 5 6 7 8 9
question_info.commands: lua __FILENAME__