Code Monkey home page Code Monkey logo

Comments (15)

delfimpandiani avatar delfimpandiani commented on June 13, 2024 2
# Test case for the algorithm
def test_stack_from_list(input_list, expected):
    result = stack_from_list(input_list)
    if expected == result:
        return True
    else:
        return False

# Code of the algorithm
from collections import deque
def stack_from_list(input_list):
    output_stack = deque()
    for item in input_list:
        output_stack.append(item)

    return output_stack
    
# Three different test runs
print(test_stack_from_list([15, 38, 56, 4], deque([15, 38, 56, 4])))
print(test_stack_from_list(["A", "B", "C", "D"], deque(["A", "B", "C", "D"])))
print(test_stack_from_list(["A", 78, "Hola", 6], deque(["A", 78, "Hola", 6])))

from 2018-2019.

SeverinJB avatar SeverinJB commented on June 13, 2024 1
from collections import deque

# Testing Algorithm
def test_stack_from_list(input_list, expected): 
    result = stack_from_list(input_list) 
    if expected == result: 
        return True 
    else: 
        return False 

# Algorithm
def stack_from_list(input_list):    
    output_stack = deque() # the stack to create 
    
    # Iterate each element in the input list and add it to the stack 
    for item in input_list: 
        output_stack.append(item) 
    
    return output_stack 

# Testing Input
print(test_stack_from_list([1,2,3,4,5], deque([1,2,3,4,5]))) 
print(test_stack_from_list(["the","answer","to","life","universe","and","everything"], deque(["the","answer","to","life","universe","and","everything"]))) 
print(test_stack_from_list(["the","ultimate","question"], deque(["the","ultimate","question"])))

from 2018-2019.

simayguzel avatar simayguzel commented on June 13, 2024 1
def test_output_stack(input_list, expected):
    result = output_stack(input_list)
    if expected == result:
        return True
    else:
        return False
from collections import deque

def output_stack(input_list):
    output_stack = deque()
    
    for item in input_list:
        output_stack.append(item)
        
        
    return output_stack

print (test_output_stack([19,18,17], deque([19,18,17])))
print (test_output_stack(["D","E","F"], deque(["D","E","F"])))
print (test_output_stack([22,"A","B"], deque([22,"A","B"])))

True
True
True

from 2018-2019.

DavideApolloni avatar DavideApolloni commented on June 13, 2024 1

screenshot at nov 29 17-29-45

from 2018-2019.

ilsamoano avatar ilsamoano commented on June 13, 2024
def test_stack_from_list(input_list, expected):
    result = stack_from_list(input_list)
    
    if expected == result:
          return True 
    else:
          return False



from collections import deque

def stack_from_list(input_list):
    output_stack = deque() 
            
    for item in input_list:
             output_stack.append(item) 
     
    return output_stack


print (test_stack_from_list([12,13,14], deque([12,13,14])))
print (test_stack_from_list(["A",13,"B"], deque(["A",13,"B"])))
print (test_stack_from_list(["A",13,"B"], deque(["B",13,"A"])))

True
True
False

from 2018-2019.

EleonoraPeruch avatar EleonoraPeruch commented on June 13, 2024

cattura2

from 2018-2019.

LuciaGiagnolini12 avatar LuciaGiagnolini12 commented on June 13, 2024
# Test case for the algorithm
def test_stack_from_list(chapters_list, expected):
    result = stack_from_list(chapters_list)
    if expected == result:
        return True
    else:
        return False

# Code of the algorithm
from collections import deque
def stack_from_list(chapters_list):
    chapters_stack = deque()
    for item in chapters_list:
        chapters_stack.append(item)

    return chapters_stack
    
# Two different test runs
print(test_stack_from_list(["chapter 1", "chapter 2", "chapter 3", "chapter 4"], deque(["chapter 1", "chapter 2", "chapter 3", "chapter 4"]))) # true
print(test_stack_from_list(["Owl Post", "Aunt Marge's Big Mistake", "The Knight Bus", "The Leaky Cauldron"], deque(["The Boggart in the Wardrobe", "Aunt Marge's Big Mistake", "The Knight Bus", "The Leaky Cauldron"]))) # false

from 2018-2019.

lisasiurina avatar lisasiurina commented on June 13, 2024

#Test case for the algorithm

def test_stack_from_list(input_list, expected):
result = stack_from_list(input_list)

if expected == result:
      return True 
else:
      return False

from collections import deque

def stack_from_list(input_list):
output_stack = deque()

for item in input_list:
         output_stack.append(item) 
 
return output_stack

print(test_stack_from_list([“Part 1", “Part 2", “Part 3", “Part 4"], deque([“Part 1", “Part 2", “Part 3", “Part 4”]))) Output: True
print(test_stack_from_list([“) “Poor Folk ", “The Double“, "The Idiot”, “A Gentle Creature“], deque(["The Double", “Poor Folk”, “The Idiot“, “A Gentle Creature“]))) Output: False

from 2018-2019.

dersuchendee avatar dersuchendee commented on June 13, 2024

Test case for the algorithm

def stack_from_list(input_list, value_to_search, expected):
result =stack_from_list(input_list, value_to_search)
if expected == result:
return True
else:
return False

from 2018-2019.

federicabologna avatar federicabologna commented on June 13, 2024
from collections import deque

def test_stack_from_list(input_list, expected):
    result = stack_from_list(input_list)
    if expected == result:
        return True
    else:
        return False

def stack_from_list(input_list):
    output_stack = deque()
    for item in input_list:
        output_stack.append(item)
    return output_stack

print(test_stack_from_list(list(["a", "b", "c"]), deque(["c", "b", "a"])))
print(test_stack_from_list(list(["d", "e", "f"]), deque(["d", "e", "f"])))

from 2018-2019.

MattiaSpadoni avatar MattiaSpadoni commented on June 13, 2024

I cannot understand why Github don't write the indentation in this case.

def test(input_list, expected):
result = createstuck(input_list)
if expected == result:
return True
else:
return False

from collections import deque
def createstack(input_list):
stack = deque()
for item in input_list:
stack.append(item)

return stack

some tests

print(createstack([55, 44, 32, 27], deque([27, 32, 44, 55]))) (True)
print(createstack(["A", "B", "C", "D"], deque(["A", "B", "C", "D"]))) (false)

from 2018-2019.

friendlynihilist avatar friendlynihilist commented on June 13, 2024
def test_stack_from_list(input_list, expected):
    result = stack_from_list(input_list)
    if expected == result:
        return True
    else:
        return False


from collections import deque
def stack_from_list(input_list):
    output_stack = deque()  # the stack to create


    for item in input_list:
        output_stack.append(item)

    return output_stack

print(test_stack_from_list(["a", "b", "c"], deque(["a", "b", "c"]))) #true
print(test_stack_from_list(["A", "b", "c"], deque(["a", "b", "c"]))) #false
print(test_stack_from_list([1, 2, 3], deque([3, 2, 1]))) #false

from 2018-2019.

andreamust avatar andreamust commented on June 13, 2024
#test stack

def test_stack_from_list(input_list, expected):
   result = stack_from_list(input_list)
   if result == expected:
       return True
   else:
       return False


from collections import deque


def stack_from_list(input_list):
   output_stack = deque()
   # Iterate each element in the input list and add it to the stack
   for item in input_list:
       output_stack.append(item)
   return output_stack


print(test_stack_from_list([62, 54, 21, 6], deque([62, 54, 21, 6]))) #True
print(test_stack_from_list(["Anna", "Marco", "Luigi", "Andrea"], deque(["Anna", "Marco", "Luigi", "Andrea"])))   #True
print(test_stack_from_list(["red", "blue", "yellow"], deque(["red", "pink"])))   #False


from 2018-2019.

tceron avatar tceron commented on June 13, 2024

from collections import deque

#test case for the algorithm
def test_stack_from_list(input_list, expected):

result = stack_from_list(input_list)
if expected == result:
    return True
else:
    return False

#code of the algorithm
def stack_from_list(input_list):
output_stack = deque() #stack to create

#iterate each element in the input list and add it to the stack
for item in input_list:
    output_stack.append(item)

return output_stack

#tests run
print(test_stack_from_list([10, 16, 82, 5], deque([10, 16, 82, 5])))
print(test_stack_from_list(["zebra", "donkey", "hippo", "giraffe"], deque(["zebra", "donkey", "hippo", "giraffe"])))

from 2018-2019.

essepuntato avatar essepuntato commented on June 13, 2024

Hi all,

First, you can find my solution as Python file in the GitHub repository.

a few very important comments for this (and future) exercise:

  1. test-driven development: all the tests must be passed in order to claim that an algorithm returns what it is expected. If a test execution return False, the test is not passed. If you need to check the non-compliancy of the execution of a function on purpose, then you have to create an additional testing function that returns True if the condition of the test is not passed. Remeber: first write the test, then develop the algorithm/function.

  2. Python code and indentation: please, in your answers to the various questions, if you have to write down a Python code, be sure that the correct indent is preserved by previewing your post before to publish it. You can use the ``` environment for defining your Python code, e.g.:


```
write your Python code here
```

from 2018-2019.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.