This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Define the gravitational constant | |
const G = 6.67430e-11; // m^3 kg^-1 s^-2 | |
/** | |
* Calculate the gravitational force between two masses. | |
* @param {number} m1 - Mass of the first object in kilograms. | |
* @param {number} m2 - Mass of the second object in kilograms. | |
* @param {number} r - Distance between the centers of the masses in meters. | |
* @returns {number} - Gravitational force in Newtons. | |
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Student: | |
def __init__(self, first_name, last_name, id_number, major, gpa=0.0, courses=[]): | |
def take_course(self, course_name): | |
self.courses.append(course_name) | |
def calculate_gpa(self, grades): | |
if len(grades) != len(self.courses): | |
print("Error: Number of grades must match number of courses enrolled in.") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Test | |
void shouldReturnAnswerWhenAnswerExists() { | |
KnowledgeRepository knowledgeRepository = | |
new InMemoryKnowledgeRepository(); | |
Answer expectedAnswer = new Answer(42, "The Ultimate"); | |
knowledgeRepository.save(expectedAnswer); | |
Answer actualAnswer = answerRepository.findAnswerToQuestion(42); | |
assertNotNull(actualAnswer); | |
assertEquals(expectedAnswer, actualAnswer); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Test | |
void shouldReturnAnswerWhenAnswerExists() { | |
User answer = KnowledgeRepository.findAnswerToQuestion(42); | |
assertNotNull(answer); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Student: | |
""" | |
This class models a student. | |
""" | |
def __init__(self, first_name, last_name, id_number, major, gpa=0.0, courses=[]): | |
""" | |
Initializes a Student object with the following attributes: | |
Args: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Student: | |
def __init__(self, name, age, student_id): | |
self.name = name | |
self.age = age | |
self.student_id = student_id | |
self.grades = [] | |
def add_grade(self, grade): | |
self.grades.append(grade) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const express = require('express'); | |
const app = express(); | |
const bodyParser = require('body-parser'); | |
const db = require('./db'); | |
// You should defined this constant in the backend | |
// Hopefully in a domain object | |
const MAX_CHARS = 255; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const express = require('express'); | |
const app = express(); | |
const bodyParser = require('body-parser'); | |
// The page architecture is over simplified | |
const db = require('./db'); | |
app.use(bodyParser.urlencoded({ extended: true })); | |
app.post('/save-data', (req, res) => { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react'; | |
// This is more closely related to real world | |
const NonExistentCustomer = () => { | |
return ( | |
<div> | |
<h2>Non Existent customer</h2> | |
<p>Sorry, we couldn't find any customer matching your criteria.</p> | |
</div> | |
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react'; | |
const NullCustomer = () => { | |
return ( | |
<div> | |
<h2>No customer found</h2> | |
<p>Sorry, we couldn't find any customer matching your criteria.</p> | |
</div> | |
); | |
}; |
NewerOlder