Category Archives: #CS

cs@worcester – Dream to Reality 2021-09-26 23:53:59

What are UML Class Diagrams

Foremost, UML diagrams

UML stands for Unified Modeling Language and was invented by Grady Booch, Ivar Jacobson, and James Rumbaugh in 1995 while working at Rational Software. We create UML diagrams to help us comprehend the system more clearly and simply. A single diagram does not represent all aspects of the system. UML defines various kinds of diagrams to cover most of the aspects of a system. UML diagram has two categories of diagrams, Structural Diagrams and Behavioral Diagram. Inside Structural Diagrams, there is Class diagram, Object diagram, Component diagram, and Deployment diagram.

UML class diagrams

Class diagrams are the most common diagrams used in UML. Classes, interfaces, relationships, and collaboration are all represented in class diagrams. The features and activities of a class, as well as the system’s restrictions, are depicted in a class diagram. Class diagrams are often used in the design of object-oriented systems since they are the only UML diagrams that can be directly mapped with object-oriented languages.

What is Class?

A Class is an object’s blueprint. Objects and classes are inextricably linked. We can’t discuss one without discussing the other. And, because we utilize classes to generate objects, the entire objective of Object-Oriented Design is not about objects, but about classes. As a result, while a class describes what an object will be, it is not the object itself. Classes, on the other hand, specify the types of things, whereas objects are useable instances of classes. Each Object was constructed using the same blueprints and so has the same components (properties and methods). An object is a member of a class and has states and behaviors, according to the standard definition.

Examples

An example can be such as there is a base class as an animal dog and we create an instance like Bobby, which is a dog. A dog has properties such as color, eye color, height, weight. And the method example for a dog can be such as a dog can jump, can sit, can eat. And for the object which is Bobby, Bobby has property value. Bobby is a yellow color, he has brown color eye; he is 17 inches tall, and he weights 24 pounds. For the methods Bobby can jump, he can sit, can eat as well.

Why UML class diagrams?

I chose this topic because UML diagrams have always made it easier for me to understand the topic/code. It helps me figure out which classes are inherited from which, which classes are abstract, and so on. For example, a class may override a method, but with the UML diagram/markdown preview, I can easily tell where the original method was created and why I have override that method. Also, since our 1st assignment is about markdown preview and UML diagrams, why not. So far, these two websites have helped me gain a better understanding of UML diagrams. https://www.tutorialspoint.com/uml/uml_standard_diagrams.htm https://www.visual-paradigm.com/guide/uml-unified-modeling-language/uml-class-diagram-tutorial/

From the blog cs@worcester – Dream to Reality by tamusandesh99 and used with permission of the author. All other rights reserved by the author.

CS Mission

Some of you may know me and some may not, but I am Sandesh Gurung and I am currently a senior at WSU pursuing a dream of becoming software developer. This is my introductory blog post for CS-343 section 2. I’m hoping to get a lot out of this lesson. It may not be easy, but it is what I most desire at the moment. As time passes, I will continue to update this blog about what I have learnt in this course. 

From the blog cs@worcester – Dream to Reality by tamusandesh99 and used with permission of the author. All other rights reserved by the author.

Reading list

The most valuable thing you can get out of any book is a list of other books worth reading. Over time, you will find that certain books keep popping up from the “bibliography”, and you should move those books to the top of the reading list. Other books will sink. Since the reading list is essentially a priority queue, you’ll eventually find that some books sink so far down the queue that you may never read them again.

Start by picking a broad book to give you a general idea of the subject you are aiming for. Then choose a few specific books to master the aspects of the topic that interest you.

Reading the right book at the right time will have a better effect. A lot of reading can improve your reading ability. You will also improve your knowledge of the outside world through reading. For computer science, reading a lot of the latest information will be of great help to your future work and research. Reading will improve your horizon and enrich your spare time.

Even if you read a good book on programming every two months, which is about 35 pages a week, it won’t take long for you to gain a deep understanding of our industry and differentiate yourself from everyone around you. — Steve McConnell, Code Complete

Focusing on the classics also carries a risk: you devote too much energy to them, at the expense of more pragmatic knowledge and information that would improve your everyday skills. Make sure to mix classics with modern, more pragmatic books and articles on your reading list.

In practice, algorithmic problems do not appear at the beginning of a large project. Then, all of a sudden, they appear as subproblems when the programmer doesn’t know how to proceed or when the current program is clearly inappropriate. — Steven S.Skiena, Scenario Analysis of The Algorithm Design Manual

From the blog haorusong by and used with permission of the author. All other rights reserved by the author.

Detailed and basic usage of Mockito

 Mockito is a Mock framework for Java single-testing, but it can also be used with other single-testing frameworks in addition to JUnit. Mockito changes the behavior of a class or object, allowing us to focus more on testing the code logic without the effort of constructing the data.

The basic concept

Mocks can be of two types, Class and Partial,so Mockito is called spy. The behavior of changing methods on mock objects is called Stub.

A Mock process is called a Mock Session, and it records all the Stubbing. It consists of three steps:

+———-+ +——+ +——–+ | Mock/Spy | ===> | Stub | ===> | Verify | +———-+ +——+ +——–+

Class Mock

A Class Mock changes the behavior of a Class so that the object it mocks completely loses its original behavior.

Method returns default values (null, false, 0, etc.) if it is not pegged.

The most basic usage is as follows:

1
2
3
4
5
6
7
8
9
10
11
12
import static org.mockito.Mockito.*;

// use List.class to creat a mock subject --- mockedList

List mockedList = mock(List.class);

//operation of mockedList

mockedList.add("one");
mockedList.clear();

//validation

verify(mockedList).add("one");
verify(mockedList).clear();

Partial Mock(spy)

If we only want to change the behavior of an instance, we need to use spy:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
List list = new LinkedList();
List spy = spy(list);

// optionally, you can stub out some methods:
when(spy.size()).thenReturn(100);

// using the spy calls *real* methods
spy.add("one");
spy.add("two");

// prints "one" - the first element of a list
System.out.println(spy.get(0));

// size() method was stubbed - 100 is printed
System.out.println(spy.size());

// optionally, you can verify
verify(spy).add("one");
verify(spy).add("two");

As you can see from the code, the main difference between a Spy and a MockSettings is that the MockSettings for a Spy needs to be passed in a SpiedInstance.

The default Answer to a spy is CALLS_REAL_METHODS, which means that if a method is not stub, it performs its real behavior.

The default Answer to a mock is RETURNS_DEFAULTS. Methods that are not stub return a default value.

source:

https://www.vogella.com/tutorials/Mockito/article.html

https://howtodoinjava.com/mockito/junit-mockito-example/

From the blog haorusong by and used with permission of the author. All other rights reserved by the author.

Use the Source

 When working on an open-source project, please get in the habit of downloading the latest version of the code (preferably from their source control system), so you can review its history and track future developments. Please take a look at the codebase structure and think about why it is organized the way it is. Look at how developers manage their code modules to see if it makes sense and compare them to how they might have used them. Try to refactor the code to understand why its coders made the decisions they did, and think about what the code would look like if you were the one coding it. It will give you a better understanding of the projects; Also, make sure you can build those projects. If you’ve found a better way to do something, you’re ready to contribute code to the project. Inevitably, as you go through the code, you’ll come across decisions you completely disagree with it. Ask yourself if the developers of the project might know something you don’t or vice versa. Consider whether this is a legacy design that needs to be refactored; consider whether making a toy implementation for the relevant feature would help clarify the issue.

You end up with a toolbox filled with all sorts of quirks that you’ve collected from other people’s code. This will hone your ability to solve minor problems more quickly and quickly. You’ll be able to tackle issues that others think are impossible to solve because they don’t have access to your toolbox. Take a look at the Git distributed source control system written by Linus Torvalds or any code written by Daniel J. Bernstein (known as DJB). Programmers like Linus and DJB occasionally use data structures and algorithms that most of us have never even heard of. They’re not magicians — they’ve just spent their time building bigger and better toolboxes than most people. The great thing about open source is that you can look at their toolbox and make their tools. One of the problems in software development is the lack of teachers. But thanks to the proliferation of open-source projects on sites such as SourceForge. Net and GitHub, you can learn from relatively representative code examples from the world’s programmer community.

In ODS, Bill Gates says: “The most subtle test of programming ability is giving the programmer about 30 pages of code and seeing how quickly he can read through it and understand it.” He realized something significant. People who quickly learn directly from the source code will soon become better programmers because their teachers are the lines of code written by every programmer in the world. The best way to learn patterns, idioms, and best practices is to read the open-source. Look at how other people to code. It’s a great way to stay relevant, and it’s free. — Chris Wanstrath at Ruby 2008 [

Pick an open-source project with deep algorithms, such as Subversion, Git, or Mercurial source control system. Browse through the project’s source code and jot down any algorithms, data structures, and design ideas that seem novel to you. Then write a blog post describing the project’s construction and highlighting the new ideas you’ve learned. Can you find a situation in your daily work where the same concept can be applied?

From the blog haorusong by and used with permission of the author. All other rights reserved by the author.

Breakable Toys

 We can all benefit from writing random “toy” programs to push ourselves to the limit by setting artificial limits. — Donald Knuth, The Art of Computer Programming

If you can learn as much from failure as you can from success, you need a relatively private space to look for the loss. In balling acrobatics, a performer who tosses three balls will never progress if he has never tossed five. Those who spend hours picking dropped balls until their back hurts eventually get good at it. The same lesson applies to software, where software workers often need to step out of their comfort zone to try something they’re not good at it. It is by taking bold chances again and again that you improve your skills, that you learn and grow from failure after failure. Just as a three-ball-tossing performer does not throw five balls in a formal performance, software developers often make mistakes in new areas. Software developers also need a safe place to make mistakes. It’s terrible not to have such a safe place to make mistakes. The fear and unwillingness of software developers to make mistakes make them stuck in a rut, unable to learn from failure, and thus makes the entire software development industry staid and stagnant.

Other examples of the “crunchy toy” pattern include games like Tetris and Tic-Tac-Toe. One senior I know has a habit of using every new language he learns to create a game, blog software, and IRC client. The nature of the problem is to build a toy that contains learning something new and provides an opportunity to let you in a special environment to deepen the understanding of hand tools. The environment is not only safe because you are the only or most influential users, and, even to the most powerful commercial products, you still have room to serve you as a user’s needs better.

You still have to remember that they’re just toys, and that’s why they’re supposed to be fun. If they’re not interesting, then when the initial excitement is over, they’ll just become a dusty relic, and you’ll be able to focus your energy on what you enjoy building.

From the blog haorusong by and used with permission of the author. All other rights reserved by the author.

DD path graphs

Structural testing is based on the source code of the program under test, rather than the definition. This is known as white box testing, while functional testing is known as black-box testing.

Program diagram: For a program written in an imperative programming language, the program diagram is a directed graph with nodes representing statement fragments and edges representing control flow.

DD – path

DD path: Decision-to-decision path (Miller). Begin with the “exit” of the decision statement and end with the “path” of the next decision statement.

DD chain: A path of starting and ending nodes at different points in a directed graph.

Consisting of a node, the internality =0;

Consisting of a node, externality =0;

Consisting of a node, the inner degree > =2 or the outer degree > =2;

Consisting of a node, the degree inside =1 and the degree outside =1;

Length > =1 for maximum drill

DD – path graph

A DD-path graph is a labeled directed graph in which nodes represent the DD Path of a program graph and edges represent the control flow of the Path.

For a given program, many different program diagrams can be constructed, all of which can be reduced to a unique DD-path diagram.

It is possible to generate DD paths for programs up to 100 lines, and above that size, analysis tools are generally required.

The simplest control flow diagram is the DD path. DD can be thought of as belonging to the control flow diagram.

DD path definition:

Given a program written in an imperative language, its DD path graph is a directed graph, where nodes represent the DD paths of its program graph and edges represent the control flow between successive DD paths.

In fact, the DD path graph is a compressed graph in which 2-connected components are compressed into a single node corresponding to the 5DD path.

source:

Click to access 08-PathTestingCoverage.pdf

From the blog haorusong by and used with permission of the author. All other rights reserved by the author.

Be the Worst

There is a saying in China: Better be the tail of a lion than a fox’s head! There is another saying: Better be the head of a chicken than the tail of a phoenix.

 

Surround yourself with developers who are better than you. Find a more robust team where you can be the weakest member and have room to grow. In the beginning, you may not feel confident in your life, but the process of developing and learning in the workplace that makes you stronger is lovely. In this society, no one will care how beautiful and challenging your strategy is. The most important thing is the result. Have you grown and become stronger during this period of enduring learning?

Remember, the probability of being rejected or thought strange by a potential mentor is not high, and the potential payoff is enormous. Even if the person isn’t interested in taking you on as a full-time apprentice, asking her out to lunch can be a valuable investment of time and money, like why dinner with Warren Buffett was auctioned off at such a high price. An early-stage businessman, or an established businessman who has achieved success in a particular field, is all vying for this opportunity. Do they care about the meal? No, they need to learn something from talking to Buffett. Such as looking at the market, investment vision, and the future development trend of business. In computer learning, the principle is the same. By talking with the people above us or the successful people, we can get the information and direction beneficial to our future development. Opportunities are for those prepared, and the accumulation of experience and insight in life will make you soar when opportunities come.

Ask lots of questions.

Tasks such as maintaining build systems, product support, responding to maintenance requirements, bug fixes, code reviews, eliminating technical debt, creating project wikis, updating documentation, acting as a sounding board for other people’s ideas, and so on. Typically, you focus on the less risky edges of the system rather than the core, which often has many dependencies and a lot of complexity. Jean Lave and Etienne Wenger look at apprenticeships in different industries and find that “in the workflow, the tasks of a novitiate are often placed at the end of a branch, rather than in the middle of a series of clips of work” (Situational Learning, p. 110). These fringe tasks benefit the team and you as an apprentice, as they are often skipped in school classes and fill in the gaps. The experience still helps when you become a skilled worker because many of your mentors understand how important it is to do the tedious work. After all, if no one cleans the floor, the team can’t do the glamorous work because it is Mired in a mess.

What’s the most grubby task your team has been putting off for months? It should be the one that everyone complains about, and nobody wants to fix. You solve it. Don’t hold your nose and force yourself to do it; See if you can solve the problem creatively in a way that exceeds people’s expectations and is fun for you. Many people feel that this is a job that is not worth their time. If you don’t do well, you will help the team take the blame. If you do well, the team will take the credit. But you grow as you solve what the team can’t do.

From the blog haorusong by and used with permission of the author. All other rights reserved by the author.

The difference between Stubs and Mocks

A mock is an object that can set an expected value, which will verify that the desired action has occurred. The stub is the object that you pass to the code under test. You can set expectations on it to work in specific ways, but those expectations are never verified. The stub’s properties will automatically behave as standard properties, and you cannot set expectations on them.

If you want to verify the code’s behavior under test, a simulation with appropriate expectations is used and validated. If you’re going to pass only values that might need to work somehow but are not the focus of the test, you can use stubs.

Important note: Stubs will never cause a test to fail. 

I believe the most significant difference is that you have written the stub with predetermined behavior. Thus, you will have a class that implements the dependencies that you have disguised for testing purposes (most likely an abstract class or interface), and a class will handle the method only through the response that is set. They don’t do anything fancy, and you’ve already written stub code for them outside of testing.

Simulations are expectations that stubs must set during testing. The simulation is not set up in a predetermined way, so you have the code to perform the simulation in your tests. The mockery is determined at run time because the code that sets expectations must be run before they do anything.

The difference between stubs and stubs

Tests written with simulation usually follow a test pattern of initialize-> set expectations -> exercise -> verify. The pre-written stub will be followed by an initialize-> exercise-> verify.

Similarities between stubs and stubs

The purpose of both is to remove all dependencies from testing a class or function so that your tests are more focused and straightforward when trying to prove it.

The most crucial difference between Stubs and Mocks is their intention. Explain this in the WHY stub and WHY simulation below

Suppose I’m writing test code for the Mac Twitter client’s public timeline controller

Here is the sample code for the test:

twitter_api.stub(:public_timeline).and_return(public_timeline_array)

client_ui.should_receive(:insert_timeline_above).with(public_timeline_array)

controller.refresh_public_timeline

Stub: The network connection to the Twitter API is very slow, which makes my tests slow. We knew it would return the timeline, so we made a stub that simulated the HTTP Twitter API so that our test could sprint, even if I were offline.


Mock: We haven’t written any UI methods yet, and I’m not sure what we need to register for UI objects. We wanted to write test code to see how my controller would work with UI objects.

In short, there is a difference between Mock and Stub objects, and RhinoMocks recognize that they allow us to write tests that better illustrate their purpose. The mock object is used to define the expectation that, in this case, I want to call the method A () with such an argument. Record and verify this expectation with ridicule. On the other hand, Stubs have a different purpose: they do not record or validate expectations but rather allow us to “replace” the behavior and state of “fake” objects to take advantage of test scenarios.

https://martinfowler.com/articles/mocksArentStubs.html

View at Medium.com

From the blog haorusong by and used with permission of the author. All other rights reserved by the author.

The Long Road

 When working on an open-source project, get in the habit of downloading the latest version of the code (preferably from their source control system) so you can review its history and track future developments. Take a look at the structure of the codebase and think about why the code is organized the way it is. Take a look at the way developers organize their code modules to see if it makes sense, and compare it to the way they might have used it. Try to refactor the code to understand why its coders made the decisions they did, and think about what the code would look like if you were the one coding it. Not only will it give you a better understanding of the projects; Also make sure you can build those projects. If you’ve found a better way to do something, you’re ready to contribute code to the project. Inevitably, as you go through the code, you’ll come across decisions you completely disagree with. Ask yourself if the developers of the project might know something you don’t or vice versa. Consider the possibility that this is a legacy design that needs to be refactored; And consider whether making a toy implementation for the relevant feature would help clarify the issue.

You end up with a toolbox filled with all sorts of quirks that you’ve collected from other people’s code. This will hone your ability to solve small problems more quickly and quickly. You’ll be able to tackle problems that others think are impossible to solve because they don’t have access to your toolbox. Take a look at the code for the Git distributed source control system written by Linus Torvalds, or any code written by Daniel J. Bernstein (known as DJB). Programmers like Linus and DJB occasionally make use of data structures and algorithms that most of us have never even heard of. They’re not magicians — they’ve just spent their time building bigger and better toolboxes than most people. The great thing about open source is that you can look at their toolbox and make their tools your own. One of the problems in software development is the lack of teachers. But thanks to the proliferation of open-source projects on sites such as SourceForge. Net and GitHub, you can learn from relatively representative code examples from the world’s programmer community.

In ODS, Bill Gates says: “The most subtle test of programming ability is giving the programmer about 30 pages of code and seeing how quickly he can read through it and understand it.” He realized something very important. People who quickly learn directly from the source code will soon become better programmers because their teachers are the lines of code written by every programmer in the world. The best way to learn patterns, idioms, and best practices is to read the open-source. Look at how other people to code. It’s a great way to stay relevant, and it’s free. — Chris Wanstrath at Ruby 2008 [

Pick an open-source project with deep algorithms, such as Subversion, Git, or Mercurial source control system. Browse through the project’s source code and jot down any algorithms, data structures, and design ideas that seem novel to you. Then write a blog post describing the structure of the project and highlighting the new ideas you’ve learned. Can you find a situation in your daily work where the same idea can be applied?

From the blog haorusong by and used with permission of the author. All other rights reserved by the author.