Happy to see unit testing making its way into the curriculum. I’ve been a software developer for 7 years now and this is one of the largest knowledge gaps we have with new devs. Test early and test often! Your designs will be better for it. And if your code is hard to test it often means you haven’t sufficiently broken down the problem into its isolated sub problems.
@BaldJewishBastard2 жыл бұрын
If you dont mind me asking, why are you watching this course if you are already developer for 7 years?
@Qwonk2 жыл бұрын
@@BaldJewishBastard Gotta stay learning. Tech changes and it's nice to have a refresher
@zyada93342 жыл бұрын
@@BaldJewishBastard being a developer for 7 years doesnt mean he learned all languages. This is not "programming" course this is "python" course
@SyphriX2 жыл бұрын
@@BaldJewishBastard fair question. Mostly because I’ve learned that relearning the basics several different ways is key to leveling up. I’m also curious about the state of computer science education and where it’s heading; the cs50 family of courses seem to be a great bellwether for that. And lastly, because cs50 kickstarted my own education back when I took it through iTunes university back in 2011. And since I couldn’t afford to attend university back then, I owe my career to free online university courses like this one. So I like to check in on them over time to see how they’ve evolved.
@mehmedkukavica80762 жыл бұрын
I graduated from the computer department at the technical college 35 years ago and we had half a math library for the problem set. We learned how to solve scientific problems with the help of computers. Now that's extreme programming. First, do the tests analytically, and then solve them numerically.. In the 1990s, it was time to program in any way. If there are errors, it's not a problem, we'll fix them when we update. That's why in the USA there are more f35s on the ground than in the air. I made programs that were 15 lines long and ran for 20 minutes on mainframe computers in the eighties. Only a computer can do those calculations. Decisions are made based on the calculations. It seems to me that technology has caught up with me. David is the generation of the nineties, the generation of the Internet, databases, information transfer: text, images,...
@Flarui2 жыл бұрын
the teacher is incredible, so much enthusiasm and energy! I understand his lectures much better than those of my teachers who mumble about half asleep and disinterested :(
@domemvs2 жыл бұрын
I agree. And he has been that way already years ago without any of these traits degrading.
@liya24285 ай бұрын
00:08 Writing our own tests to ensure correct solutions 02:20 Testing unit tests and controlling main function execution 06:13 Testing code functionality using unit tests. 08:08 A mistake in the square function caused a test to fail 12:11 Introduction to using try and except in Python for error handling 14:16 Writing comprehensive unit tests helps catch discrepancies in code logic 17:51 Unit testing is a formal way of testing individual function units. 19:37 Using pytest to automate the testing process 23:13 Testing user input for different data types. 25:04 Unit testing and its importance in controlling program's output 28:39 Divide tests into separate categories for better debugging insights 30:26 Identifying and fixing failing unit tests 34:01 Unit testing frameworks automate the process of catching exceptions, making testing more efficient. 35:54 Testing for type error by deliberately passing a string to the square function. 39:43 Testing a function with arguments and return values 41:38 Functions should either return a value or have side effects, not both. 45:26 Writing multiple tests helps in identifying bugs more easily 47:25 Keep tests simple and small to avoid complexities and flaws.
@ansumanroutray1118 Жыл бұрын
it is just amazing how this teacher, teaches complex topics of easily, that is easy to understand.
@cleidysbrooks2 жыл бұрын
Good Morning Python Family. I like this lectures very good teaching. David you are the best!
@حسنين-ذ6ل7 ай бұрын
you have to name the file you want to test with "test_(anything)" in order to use pytest this also applies for all the function inside that file
@yqhanliving10 ай бұрын
So useful to learn unit test and structuring the code with a testable design. Thank you cs50 team!
@MrTomro2 жыл бұрын
amazing! the teacher is so enthusiastic and i watched this whole thing in one go without any problem
@njmanga6172 жыл бұрын
Love your lectures i completed the cs50 to python and loved it, it was well worth the time and effort
@mwlk95082 ай бұрын
amazing so far. I learnt so much things so far. I did many programming courses in the past. But this the best one that actually teach me the concepts properly.
@williamenur3404 Жыл бұрын
My progress is awesome thank CS50
@RGen-z5 ай бұрын
Legendary quality🙏🏾 Thank you so much for the opportunity to learn
@falaknaaz756926 күн бұрын
awesome lectures
@evachen8623 Жыл бұрын
Thank you Daivid as always~🥰
@rounakpatra22102 жыл бұрын
It will be great if cs50 provides basic of DSA using python
@bigbro18157 ай бұрын
Thanks David
@eashwaransridhar252 Жыл бұрын
For folks who are facing an issue 20:42 to run pytest sting an issue "pytest iis not recognized as an internal or external command " You can use the command : python -m pytest "Test file name"
@Tomharry910 Жыл бұрын
It worked. Thanks!
@ElliotWayne44018 ай бұрын
when i write , from (name of the file) import function ,it tells me that it cant read the name of the file
@eashwaransridhar2528 ай бұрын
@@ElliotWayne4401 Check witht the permission of the file ,Can it be acessed to other user also ,In windiws its a headache but in linux its prettty simple
@ziyaadmallick91924 ай бұрын
It worked but what's the reason behind it saying it doesn't recognize pytest as a cmdlet, function etc
Wouldn't it be easier to make a dictionary or a list of tuples with input and expected output to a function, and then call all of them with a for loop and print out which ones failed? That way you are repeating yourself less (writing the name function you are testing, writing assert, writing separate functions for categories). You just have to write the inputs and outputs in a dictionary like this { ("input param", "input param2") : "expected output", ... }
@panos.fasoulas Жыл бұрын
strange to me that this question is not answered. your question to me as a beginner is a question i d like to know the answer.
@jgojiz5 ай бұрын
thank you! 💖💖
@martinp78412 жыл бұрын
These lectures are nice but why is the video screen SOOOO bright? I need sunglasses to watch.
@justmantate Жыл бұрын
cause it’s green screen I guess
@ethanrojas2270 Жыл бұрын
Or because 😮 Malan is super bright 💡
@Ancient-Africa4 ай бұрын
Lol... The person who made devices brightness adjustable: Am I a joke to you😂
@mahmutpekkara6 сағат бұрын
44:33 assert added to the line 5
@cs50memepage22 жыл бұрын
Don't try to solve serious matters in the middle of the night.
@novacoax2 жыл бұрын
I do that all the time 😂
@nomelastname37712 жыл бұрын
@cs50 I understand what u mean, and i agree. Don't do important things when u are tired. It will be ease to forget something or other bad thing
@sayori39392 жыл бұрын
If you have the actual solution then go ahead if you're just assuming things better leave it to the next day
@NikiruSan4 ай бұрын
I did that, and now It's already morning.😢
@LAAL0_O5 ай бұрын
can't wait for the exercise to be 100x harder than this lecture.
@jonnysegway78663 ай бұрын
this is the way!
@オズ-o8p2 ай бұрын
44:41 don't forget to add "assert" in your code guys
@mahipalmahato7648 Жыл бұрын
start at 36:02
@fslurrehman2 жыл бұрын
Instead of try , shortcut is to use comma and then error message string in front of assert.
@sayori39392 жыл бұрын
Gimme a code example :0
@tacy91 Жыл бұрын
@@sayori3939 assert square(3) == 9, "3 squared was not equal to 9"
@sayori3939 Жыл бұрын
@@tacy91 huh neat
@Yukishuru2 жыл бұрын
Nice
@AniruddhaKarmakar-r6t11 ай бұрын
@evylrune2 жыл бұрын
"pytest calculator_test.py" in the terminal gives me: "The term 'pytest' is not recognized as a name of a cmdlet, function, script file, or executable program." I did install and update it with pip (Python and visual studio code are also installed in their default installation folders). Then I found this online: "python -m pytest" which does run the test on my file fine... Is there a way to make the normal pytest command work?
@doc_parallex61392 жыл бұрын
you have to install pytest to be able to use it so in the terminal type: pip install pytest hope that helps
@sayori39392 жыл бұрын
@@doc_parallex6139 i installed a ransomware and now i am being hold captive after writing that command :/ I'm kidding :3
@vishnubhat2084 Жыл бұрын
nice
@destroyer9802 жыл бұрын
I know nothing about coding and i am watching this 😅
@novacoax2 жыл бұрын
😂
@mariamorozova53602 жыл бұрын
I was going to watch a movie but this stream changed my plans
@novacoax2 жыл бұрын
@@mariamorozova5360 you'll enjoy it. David J. is a great lecturer
@mariamorozova53602 жыл бұрын
@@novacoax yeah he is! I wathed CS50 already and now this course
@spht9ng2 жыл бұрын
Watch the first one in the series and learn a new skill. it's quite a bit of fun
@anismadrid2645 Жыл бұрын
The fact that only few people watch this is so sad 😶 Thanks world
@chrislachman20109 ай бұрын
It's not sad, it's less competition.
@faith231q2 жыл бұрын
For the problem set5, I'm getting the error in Refueling. It says: :( correct fuel.py passes all test_fuel.py checks expected exit code 0, not 2. Someone please help why am I getting this error. Would really appreciate your help
@kumaraperumal Жыл бұрын
maybe you used sys.exit(2) insted of sys.exit(0)
@حسنين-ذ6ل7 ай бұрын
this might help :- try naming the file you want to test with "test_(anything)"and then use pytest this also applies for all the function inside that file
@jaytep56473 ай бұрын
44:31 Line 5 of test_hello.py is missing the keyword assert, this is fixed when the camera switches but still worth pointing out
@milorodval678 Жыл бұрын
When I test the "hello.py" it's everything OK, but when I run it with "python hello.py" and I don't pass a name it does not give me the default (that should be "world"). It gives me nothing.
@bartoalheiros36169 ай бұрын
I'm using Python 3.12.1, pytest-8.0.0, and, when I do the check ->> hello("David") == "hello, David" with the print( ) function on the hello( ) function like this: def hello(to="world"): print("hello, ", {to}) that pass.
@srisaisubramanyamdavanam99122 жыл бұрын
Would this course will be easy for those who taken already cs50 introduction to computer science course
@gojosensei65012 жыл бұрын
Obviously are u stupid
@sayori39392 жыл бұрын
Idk, this is easier than cs50x but some problems sets have some obscure solutions or I'm the one obscure ._. but I've already come this far, cs50x took me some months
@ethanrojas2270 Жыл бұрын
46:15 dr.malan “if or oh of “
@oyekanmibamidele61962 жыл бұрын
I'm aiye I'm alive l can't deny this...Peyton is beautiful to know.
@sayori39392 жыл бұрын
Who's "Peyton"?
@fredoverflow Жыл бұрын
@@sayori3939 Simon Peyton Jones?
@billionairesbio2 жыл бұрын
HELLO... ..THIS IS CS50 ....
@souvikmoitra6700 Жыл бұрын
I have a question when two of the functions failed, and one passed but then also the 100% test failed was encountered but it should be 66.66% right ??
@BhavyamMittal-gi3jn Жыл бұрын
I tried doing the pytest but this is what it tells me: "The term 'pytest' is not recognized as a name of a cmdlet, function, script file, or executable program." I did install it with pip (Python and visual studio code are also installed in their default installation folders). How do I make it work?
@sayori39392 жыл бұрын
Aawwwn whenever i reach the end of a lesson i feel a little bit empty :/
@benc79102 жыл бұрын
what vscode theme is this ?
@MightyBaja8 ай бұрын
Okay the unit test exercises are are hard... check50 just gives yellow checks on my pytest
@allbusiness54023 ай бұрын
48:14 Whats mkdir test?? And what does code test/test_hello.py mean? Did I miss something?
@umair58072 жыл бұрын
Sir, is there any book for CS50 for exercises ?
@StreamAod12 күн бұрын
i am having a problem in implementing unit test ,because i dont know why but in my cs50 compiler I am not able to import my functions from actual code file to test file . please if somebody can help me with this .
@umair58072 жыл бұрын
23:15 Sir I got an error, when I type "pytest test_calculator.py" in terminal. I got this error: The term 'pytest' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. Im using pyCharm. what's the problem sir?
@BrendaAnderson2 жыл бұрын
You will have to install it. www.jetbrains.com/help/pycharm/pytest.html#enable-pytest (if the link doesn't work, google pytest in pycharm and it should lead you there.
@GrimmReaper3185Ай бұрын
Then more i learn the harder this gets. should 'nt it be easier?
@XTremeTerrorSquad Жыл бұрын
Hi, did anyone used free certificate in their resume?
@koshobai Жыл бұрын
There's definitely no harm in it. I even put my GitHub profile on my resume.
@appleapple17632 жыл бұрын
35:03 Am I the only person that the float like 1.2 works in this code? assert square(1.2)==1.44 it works totally fine for me
@fredoverflow Жыл бұрын
assert square(0.1) == 0.01
@rikmoran3963 Жыл бұрын
Did you not listen to his explanation? He said that he wasn't testing for floats (which of course could have many decimal places) because the result may include rounding which makes it harder to assert the correct answer. He clearly wasn't referring to something as simple as 1.2. He was only testing the expected input.
@danho24412 жыл бұрын
The __name__ variable isn’t well explained.
@ethanrojas2270 Жыл бұрын
I know
@hasty-prize990010 ай бұрын
@@ethanrojas2270 without the __name__ function in this video if you were to import a function from another file , when you run it main will automatically run with it.
@huwrw007 Жыл бұрын
15:00
@bluegrapes2010 Жыл бұрын
AT 4:22, what does if __name__ == "__main__": mean? can anyone explain to me? Thanks,
@jamessadler851 Жыл бұрын
It's incase your code is imported into another python file
@bluegrapes2010 Жыл бұрын
@@jamessadler851thanks!
@demonking10632 жыл бұрын
remove hdr
@sayori39392 жыл бұрын
Why? In my old computer they look fine and my phone too...
@koshobai Жыл бұрын
Yes HDR is here to stay.
@HungryTv13 Жыл бұрын
47:47
@ThomasKroll-ch7nb Жыл бұрын
The lectures are great, but check50 is a joke. Check50 returns results which are inconsistent with pytest and only returns vague errors like "expected exit code 0 not 1" which can not be duplicated outside of check50. Harvard should be embarrassed to publish a learning tool this unreliable.
@qqmayakashi Жыл бұрын
why did the result at 37:53 passed? it should be failed as we must only accept integers at function square
@qqmayakashi Жыл бұрын
everytime i instead use the with pytest.raises(ValueError) instead of TypeError, i always catch the error but the pytest shows it catches typeError. But if i use TypeError, it does not catch any anomalies on square("cat")
@rikmoran3963 Жыл бұрын
I think you missed the point. He is telling the test program that if someone enters a str value into the square() function it will generate a TypeError error. When the test program runs it trys the string "cat" and does indeed generate a TypeError. This is expected behaviour and therefore correct. We are testing the square() function, not the main() function from the module which is the one that handles the input.
@brianholmes16552 жыл бұрын
I appreciate that these videos are in HDR, but having a predominantly white background that is > 200 nits (at least) makes the videos essentially unwatchable at night and an unnecessary drain on battery during the day.
@RoccoCampana Жыл бұрын
@@mondo_burrito Sometimes you just gotta look on the bright side.
@hernandezlopezmiguelangel276 Жыл бұрын
Hi to everyone in the minute 23:15 I got an error, when I type "pytest test_calculator.py" in terminal. I got this error: The term 'pytest' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. I'm using VS code. does anyone knows how to fix the problem?:(
@davidjmalan Жыл бұрын
Be sure to use code.cs50.io !
@jacquessantiago Жыл бұрын
You'd have to "pip install pytest" first
@24bit192khtz4 ай бұрын
The false American accent by those Desi guys who are asking questions, is quite irritating!
@dhruvrathod324 ай бұрын
ur here to learn, buffoon!
@atasagun1437 Жыл бұрын
boring
@sayori39392 жыл бұрын
WARNING: this problem set has a. Lot of BS specially that "refueling" one. If you write the test code "correctly" but doesn't use that quirky pytest.raises, check50 gives you the absolute most nonsense message and doesn't complete any check, if you indid use that pytest.raises but in the fuel.py code catch the ValueError, ZeroDivisionError inside a try block check50 passes but pytest complains saying DiD NOt RaISe ZeroDivisionError OBS: if you explicitly *RAISE* those exceptions inside a try via "if" or whatever it eill not detected it, you have to use the ifs/raise outside any try blocks 😠😠😠 tht made me so angry!
@MightyBaja8 ай бұрын
Faced the same problem...had to submit it because it's been days trying to figure it out