The code:
def isPalindrome(text): """ >>> isPalindrome("alula") True >>> isPalindrome("love") False >>> isPalindrome("Madam") True >>> isPalindrome(12.5) False >>> isPalindrome(12.21) False >>> isPalindrome("Cigar? Toss it in a can.! It is so tragic.") True >>> isPalindrome("travel.. a town in Alaska") False """ # --- YOU CODE STARTS HERE if type(text) is not str: return False l = len(text) - 1 i = 0 while i < l: if text[i] in string.punctuation or text[i] == ' ': i += 1 elif text[l] in string.punctuation or text[l] == ' ': l -= 1 elif text[i].upper() != text[l].upper(): return False else: i += 1 l -= 1 return True
--------------------------------------------------------------
Write the test.py script to perform your testing for your isPalindrome function using the unittest module and prove that it works correctly. Remember to be as descriptive as possible and write as many cases as necessary (check the Hands On video for examples of a description). Unittest is intended to run test cases in bulk, so it should contain enough test cases to prove your code works. Your script should contain at least 6 cases with 3 tests per case. Examples of cases are testing words, lowercase, uppercase, mixed letters, sentences, strings with punctuation, spaces, input that is not a string, etc. You can discuss, suggest and share possible edge cases on Piazza. Do not include the doctest examples in your unittest file
-------------------------------------------------------------
CODE NEEDED: import unittest from LAB4 import * class PalindromeTestCases(unittest.TestCase): """Tests for LAB4.py""" #Do not modify the 2 lines below if __name__ == '__main__': unittest.main(exit=False)
Here is the completed code for this problem. Comments are included, go through it, learn how things work and let me know if you have any doubts or if you need anything to change. If you are satisfied with the solution, please rate the answer. Thanks
#code
import unittest
from LAB4 import *
class
PalindromeTestCases(unittest.TestCase):
"""Tests for LAB4.py"""
def
test_single_words(self):
"""testing single
words"""
self.assertTrue(isPalindrome('Hannah'),
"'Hannah' should be a palindrome")
self.assertFalse(isPalindrome('Kevin'),
"'Kevin' is not a palindrome")
self.assertTrue(isPalindrome('P'), "'P'
should be a palindrome")
def
test_lower_case(self):
"""testing input in
lower case"""
self.assertTrue(isPalindrome('abcdcba'),
"'abcdcba' should be a palindrome")
self.assertFalse(isPalindrome('python'),
"'python' is not a palindrome")
self.assertTrue(isPalindrome('crazyyzarc'),
"'crazyyzarc' should be a palindrome")
def
test_upper_case(self):
"""testing input in
upper case"""
self.assertTrue(isPalindrome('ABCDCBA'),
"'ABCDCBA' should be a palindrome")
self.assertFalse(isPalindrome('PYTHON'),
"'PYTHON' is not a palindrome")
self.assertTrue(isPalindrome('CRAZYYZARC'),
"'CRAZYYZARC' should be a palindrome")
def
test_mixed_case(self):
"""testing input in mixed
case"""
self.assertTrue(isPalindrome('AbcDcBA'),
"'AbcDcBA' should be a palindrome")
self.assertFalse(isPalindrome('pYThon'),
"'pYThon' is not a palindrome")
self.assertTrue(isPalindrome('crAzYyZARC'),
"'crAzYyZARC' should be a palindrome")
def test_sentences(self):
"""testing
sentences"""
self.assertTrue(isPalindrome("Madam I'm Adam"),
"'Madam I'm Adam' should be a palindrome")
self.assertFalse(isPalindrome("Madam I'm Eve"),
"'Madam I'm Eve' is not a palindrome")
self.assertTrue(isPalindrome("Sit on a potato pan,
Otis"), "'Sit on a potato pan, Otis' should be a
palindrome")
def
test_sentences_with_special_chars(self):
"""testing input
with special characters"""
self.assertTrue(isPalindrome("Ma d;am I;;''m
A#da'm"), "'Ma d;am I;;''m A#da'm' should be a
palindrome")
self.assertFalse(isPalindrome(";M;adam I'm Eve"),
"';M;adam I'm Eve' is not a palindrome")
self.assertTrue(isPalindrome(";S>>i''' t o] n a
p:ota@to p!a!n, Oti{s"), "';S>>i''' t o] n a
p:ota@to p!a!n, Oti{s' should be a palindrome")
def
test_different_type_input(self):
"""testing input in
different data types"""
self.assertFalse(isPalindrome(123),'123 is not a palindrome
string')
self.assertFalse(isPalindrome([0.2,1.4,5.6]),
'[0.2,1.4,5.6] is not a palindrome string')
#passing a boolean
value to isPalindrome
self.assertFalse(isPalindrome(isPalindrome('S')),
'isPalindrome("S") is not a palindrome
string')
# Do not modify the 2 lines below
if __name__ == '__main__':
unittest.main(exit=False)
#output
.......
----------------------------------------------------------------------
Ran 7 tests in 0.000s
OK
The code: def isPalindrome(text): """ >>> isPalindrome("alula") True...
using the following solve using python and use the code at bottom of page to run test MUST PAST ALL TESTS def if_function(condition, true_result, false_result): """Return true_result if condition is a true value, and false_result otherwise. >>> if_function(True, 2, 3) 2 >>> if_function(False, 2, 3) 3 >>> if_function(3==2, 3+2, 3-2) 1 >>> if_function(3>2, 3+2, 3-2) 5 """ if condition: return true_result else: return false_result def with_if_statement(): """ >>> with_if_statement() 1 """ if c(): return t() else: return f() def with_if_function():...
Please write a code in Java where it says your // your code here to run the code smoothly. Import statements are not allowed. _ A Java method is a collection of statements that are grouped together to perform an operation. Some languages also call this operation a Function. When you call the System.out.println() method, for example, the system actually executes several statements in order to display a message on the console. Please write the code according to functions assigned...
Please write a code in Java where it says your // your code here to run the code smoothly. Import statements are not allowed for this assignment, so don't use them. _ A Java method is a collection of statements that are grouped together to perform an operation. Some languages also call this operation a Function. When you call the System.out.println() method, for example, the system actually executes several statements in order to display a message on the console. Please...
(Please help me with Coding in Python3) AVLTree complete the following implementation of the balanced (AVL) binary search tree. Note that you should not be implementing the map-based API described in the plain (unbalanced) BSTree notebook — i.e., nodes in the AVLTree will only contain a single value. class AVLTree: class Node: def __init__(self, val, left=None, right=None): self.val = val self.left = left self.right = right def rotate_right(self): n = self.left self.val, n.val = n.val, self.val self.left, n.left, self.right, n.right...
This assignment is designed to give you practice with Javadoc, creating unit tests and using Junit. Be sure to follow all style and documentation requirements for THIS class. See the style and documentation requirements posted on Canvas. You are to name your package assign1 and your file Palindrome.java. Palindrome Class Palindrome testString : String + Palindrome (String) + isPalindrome (): boolean The method isPalindrome is to determine if a string is a palindrome. A palindrome, for this assignment, is defined...
COMPLETE THE _CONSTRUCT() AND CONSTRUCTTREE() FUNCTIONS class expressionTree: class treeNode: def __init__(self, value, lchild, rchild): self.value, self.lchild, self.rchild = value, lchild, rchild def __init__(self): self.treeRoot = None #utility functions for constructTree def mask(self, s): nestLevel = 0 masked = list(s) for i in range(len(s)): if s[i]==")": nestLevel -=1 elif s[i]=="(": nestLevel += 1 if nestLevel>0 and not (s[i]=="(" and nestLevel==1): masked[i]=" " return "".join(masked) def isNumber(self, expr): mys=s.strip() if len(mys)==0 or not isinstance(mys, str): print("type mismatch error: isNumber")...
Background An anagram is a word phrase, or name formed by rearranging the letters of another, such as the word "cinema", formed from 'iceman". Problem Statement Given two strings s and t, write a function to determine ift is an anagram of S. A sample main function is provided so that you may test your code on sample inputs. Inputs can be provided in the box below your code, please format your input as follows: Example input nose soen Requirements...
YOU MUST NOT MAKE ANY CHANGES TO THAT CODE package edu.buffalo.cse116; /** * Class that can be used to test if two integers are coprime. Numbers are considered coprime iff the largest divisor * shared by both numbers is 1. Identifying coprime (also called relatively prime) numbers is valuable for RSA public * key cryptography (and possibly other things, but the author has never seen any other uses). */ public class CoprimeNumbers { /** * Given two integers, this returns...
Python code. NO importing modules. you may not use: contains(), index(), sum(),join(), split(). def column_cipher(plaintext): • Parameter(s): plaintext ----- a string; the message to be encrypted • Return value: A string; the ciphertext after applying the column cipher algorithm • Assumptions: o The standard English alphabet is used: "abcdefghijklmnopqrstuvwxyz" o All strings will be non-empty, entirely lowercase, and only contain valid letters in the alphabet. • How it works: o First, transpose the text into 5 different columns by writing...
Please write the code in a text editor and explain thank you! 1. LINKED-LIST: Implement a function that finds if a given value is present in a linked-list. The function should look for the first occurrence of the value and return a true if the value is present or false if it is not present in the list. Your code should work on a linked-list of any size including an empty list. Your solution must be RECURSIVE. Non-recursive solutions will...